Browse Source

compdfkit(win) - 数字签名模块切换,View模块

liuaoran 1 year ago
parent
commit
283899d613

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Common/BarControl/CPDFDigitalSignatureBarControl.xaml.cs

@@ -155,6 +155,7 @@ namespace Compdfkit_Tools.Common
                 DigitalSignatureActionChanged?.Invoke(sender, DigitalSignatureAction.VerifySignature);
             }
         }
+
         #endregion
     }
 }

+ 5 - 4
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml

@@ -6,9 +6,7 @@
              xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              xmlns:cpdftools="clr-namespace:Compdfkit_Tools.PDFControl"
              mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800" 
-             Loaded="UserControl_Loaded"
-             Unloaded="UserControl_UnLoaded">
+             d:DesignHeight="450" d:DesignWidth="800">
     <UserControl.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
@@ -46,7 +44,7 @@
         <Border x:Name="ToolBarContainer" Height="45" Visibility="Visible" BorderThickness="1" BorderBrush="#1A000000" Background="#F2F3F5" Grid.ColumnSpan="4">
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                 <StackPanel Orientation="Horizontal">
-                    <cpdfcommon:CPDFDigitalSignatureBarControl x:Name="DigitalSignatureBarControl" Loaded="AnnotationBarControl_Loaded" Unloaded="DigitalSignatureBarControl_Unloaded" Height="44"/>
+                    <cpdfcommon:CPDFDigitalSignatureBarControl x:Name="DigitalSignatureBarControl" Height="44"/>
                     <Line Height="40" Stroke="#D5D6D8" StrokeThickness="2" X1="0" Y1="10" X2="0" Y2="30" Margin="8,0,8,0" />
                     <Button Name="UndoBtn" Style="{StaticResource LightButtonStyle}" BorderThickness="0"  Width="40" Height="40" IsEnabled="{Binding CanUndo,Mode=OneWay}"  Click="UndoButton_Click"
                                     Background="Transparent">
@@ -117,5 +115,8 @@
                 </ControlTemplate>
             </GridSplitter.Template>
         </GridSplitter>
+        <Border x:Name="PDFGrid" Background="#CECECE" Grid.Row="1" Grid.Column="2"></Border>
+        <Border x:Name="PropertyContainer" Grid.Column="3" Grid.Row="1" Visibility="Collapsed"></Border>
+        <cpdfcommon:PageNumberControl x:Name="FloatPageTool" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,20"></cpdfcommon:PageNumberControl>
     </Grid>
 </UserControl>

+ 52 - 13
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -1,4 +1,5 @@
 using Compdfkit_Tools.PDFControl;
+using ComPDFKitViewer.PdfViewer;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -26,6 +27,7 @@ namespace Compdfkit_Tools.PDFControl
         private bool isFirstLoad = true;
         public PDFViewControl PdfViewControl = new PDFViewControl();
         private bool _isActive = false;
+        public event EventHandler<bool> OnCanSaveChanged;
 
         public event PropertyChangedEventHandler PropertyChanged;
         protected void OnPropertyChanged([CallerMemberName] string name = null)
@@ -68,32 +70,60 @@ namespace Compdfkit_Tools.PDFControl
                 return false;
             }
         }
+
+        private bool CanSave
+        {
+            get
+            {
+                if (PdfViewControl != null && PdfViewControl.PDFView != null)
+                {
+                    return PdfViewControl.PDFView.UndoManager.CanSave;
+                }
+
+                return false;
+            }
+        }
         public DigitalSignatureControl()
         {
             InitializeComponent();
+            DataContext = this;
         }
 
-
-        private void UserControl_Loaded(object sender, RoutedEventArgs e)
+        public void ClearViewerControl()
         {
-
+            PDFGrid.Child = null;
+            BotaContainer.Child = null;
+            PropertyContainer.Child = null;
         }
 
-        private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
+        public void InitWithPDFViewer(CPDFViewer pdfViewer)
         {
-
+            PdfViewControl.PDFView = pdfViewer;
+            PDFGrid.Child = PdfViewControl;
+            FloatPageTool.InitWithPDFViewer(pdfViewer);
+            InitialControl();
         }
 
-        private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
+        private void InitialControl()
         {
-
+            PdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
+            //PdfViewControl.PDFView?.Load();
+            PdfViewControl.PDFView?.SetShowLink(true);
+            PDFGrid.Child = PdfViewControl;
+            PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
+            PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
+            PdfViewControl.PDFView.SetFormFieldHighlight(true);
         }
 
-        private void DigitalSignatureBarControl_Unloaded(object sender, RoutedEventArgs e)
+        /// <summary>
+        /// Undo Redo Event Noitfy
+        /// </summary>
+        private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
-            if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
+            OnPropertyChanged(e.PropertyName);
+            if (e.PropertyName == "CanSave")
             {
-                PdfViewControl.PDFView.UndoManager?.Undo();
+                OnCanSaveChanged?.Invoke(this, CanSave);
             }
         }
 
@@ -107,17 +137,26 @@ namespace Compdfkit_Tools.PDFControl
 
         private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
         {
-
+            if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
+            {
+                PdfViewControl.PDFView.UndoManager?.Redo();
+            }
         }
 
         private void UndoButton_Click(object sender, RoutedEventArgs e)
         {
-
+            if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
+            {
+                PdfViewControl.PDFView.UndoManager?.Undo();
+            }
         }
 
         private void RedoButton_Click(object sender, RoutedEventArgs e)
         {
-
+            if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
+            {
+                PdfViewControl.PDFView.UndoManager?.Redo();
+            }
         }
     }
 }

+ 0 - 1
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -127,7 +127,6 @@ namespace Compdfkit_Tools.PDFControl
             PDFGrid.Child = PdfViewControl;
 
             panelState.PropertyChanged += PanelState_PropertyChanged; 
-            DataContext = this;
         }
 
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)

+ 5 - 4
Demo/Examples/Compdfkit_Tools/PDFView/RegularViewerControl.xaml.cs

@@ -24,6 +24,10 @@ namespace Compdfkit_Tools.PDFView
         public CPDFAnnotationControl PDFAnnotationControl = new CPDFAnnotationControl();
         private CPDFDisplaySettingsControl displaySettingsControl = null;
         private PanelState panelState = PanelState.GetInstance();
+        private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
+        public event PropertyChangedEventHandler PropertyChanged;
+        public event EventHandler<bool> OnCanSaveChanged;
+
         private bool _isActive = false;
         public bool IsActive
         {
@@ -32,12 +36,9 @@ namespace Compdfkit_Tools.PDFView
             set
             {
                 _isActive = value;
-                OnPropertyChanged(); 
+                OnPropertyChanged();
             }
         }
-        private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
-        public event PropertyChangedEventHandler PropertyChanged;
-        public event EventHandler<bool> OnCanSaveChanged;
 
         private bool CanSave
         {

+ 23 - 1
Demo/Examples/DigitalSignature/App.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using ComPDFKit.NativeMethod;
+using Compdfkit_Tools.Helper;
+using System;
 using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
@@ -13,5 +15,25 @@ namespace DigitalSignature
     /// </summary>
     public partial class App : Application
     {
+        protected override void OnStartup(StartupEventArgs e)
+        { 
+            base.OnStartup(e);
+            LicenseVerify();
+        }
+
+        private static bool LicenseVerify()
+        {
+            bool result = false;
+
+            result = CPDFSDKVerifier.LoadNativeLibrary();
+            if (!result)
+                return false;
+            SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
+
+            LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
+            if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
+                return false;
+            return result;
+        }
     }
 }

+ 9 - 1
Demo/Examples/DigitalSignature/DigitalSignature.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{DD286D3B-0690-43D7-A3BA-AF8680FAD301}</ProjectGuid>
     <OutputType>WinExe</OutputType>
     <RootNamespace>DigitalSignature</RootNamespace>
-    <AssemblyName>DigitalSignature</AssemblyName>
+    <AssemblyName>Forms_ComPDFKit</AssemblyName>
     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@@ -94,6 +94,14 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
+    <Content Include="..\license_key_windows.xml">
+      <Link>license_key_windows.xml</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+    <Content Include="..\TestFile\PDF32000_2008.pdf">
+      <Link>PDF32000_2008.pdf</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>

+ 6 - 6
Demo/Examples/DigitalSignature/MainWindow.xaml

@@ -7,6 +7,8 @@
          xmlns:cpdftools="clr-namespace:Compdfkit_Tools.PDFControl;assembly=Compdfkit_Tools"
         xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common;assembly=Compdfkit_Tools"
         mc:Ignorable="d"
+        Loaded="Window_Loaded"
+        Unloaded="Window_Unloaded"
         Title="MainWindow" Height="450" Width="800">
     <Window.Resources>
         <ResourceDictionary>
@@ -116,9 +118,9 @@
 
                     <cpdftools:CPDFScalingControl x:Name="CPDFSaclingControl"></cpdftools:CPDFScalingControl>
                 </StackPanel>
-                <ComboBox Name="ModeComboBox" Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" Tag="Viewer">Viewer</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Digital Signature">Form</ComboBoxItem>
+                <ComboBox Name="ModeComboBox" Style="{StaticResource ComboBoxStyle1}" Width="150" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
+                    <ComboBoxItem Tag="Viewer">Viewer</ComboBoxItem>
+                    <ComboBoxItem Tag="Digital Signature" IsSelected="True">Digital Signature</ComboBoxItem>
                 </ComboBox>
                 <StackPanel Orientation="Horizontal" Grid.Column="2">
 
@@ -224,9 +226,7 @@
                             <ColumnDefinition></ColumnDefinition>
                             <ColumnDefinition Width="auto"></ColumnDefinition>
                         </Grid.ColumnDefinitions>
-                        <Border x:Name="PDFGrid" Background="#CECECE">
-                            <cpdftools:DigitalSignatureControl></cpdftools:DigitalSignatureControl>
-                        </Border>
+                        <Border x:Name="PDFGrid" Background="#CECECE"></Border>
                     </Grid>
                 </Grid>
             </Grid>

+ 214 - 2
Demo/Examples/DigitalSignature/MainWindow.xaml.cs

@@ -1,6 +1,13 @@
-using System;
+using Compdfkit_Tools.Helper;
+using Compdfkit_Tools.PDFControl;
+using Compdfkit_Tools.PDFView;
+using ComPDFKitViewer;
+using ComPDFKitViewer.PdfViewer;
+using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
@@ -18,13 +25,168 @@ namespace DigitalSignature
     /// <summary>
     /// MainWindow.xaml 的交互逻辑
     /// </summary>
-    public partial class MainWindow : Window
+    public partial class MainWindow : Window, INotifyPropertyChanged
     {
+        private string currentMode = "Viewer";
+
+        private PDFViewControl pdfViewer;
+        private PDFViewControl passwordViewer;
+        private RegularViewerControl regularViewerControl = new RegularViewerControl();
+        private DigitalSignatureControl digitalSignatureControl = new DigitalSignatureControl();
+        private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
+        private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
+
+        private PanelState panelState = PanelState.GetInstance();
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+
+        private bool _canSave = false;
+        public bool CanSave
+        {
+            get => _canSave;
+            set
+            {
+                _canSave = value;
+                OnPropertyChanged();
+            }
+        }
+
+        public bool LeftToolPanelButtonIsChecked
+        {
+            get => panelState.IsLeftPanelExpand;
+            set
+            {
+                panelState.IsLeftPanelExpand = value;
+                OnPropertyChanged();
+            }
+        }
+
+        public bool RightToolPanelButtonIsChecked
+        {
+            get
+            {
+                return (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel);
+            }
+            set
+            {
+                panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
+                OnPropertyChanged();
+            }
+        }
+
+        public bool ViewSettingBtnIsChecked
+        {
+            get
+            {
+                return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
+            }
+            set
+            {
+                panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
+                OnPropertyChanged();
+            }
+        }
+
         public MainWindow()
         {
             InitializeComponent();
+            DataContext = this;
+        }
+
+        #region Load Document
+        private void LoadDefaultDocument()
+        {
+            string defaultFilePath = "PDF32000_2008.pdf";
+            pdfViewer.PDFView.InitDocument(defaultFilePath);
+            LoadDocument();
+        }
+
+        private void LoadCustomControl()
+        {
+            regularViewerControl.PdfViewControl = pdfViewer;
+            regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
+            regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+            regularViewerControl.SetBOTAContainer(null);
+            regularViewerControl.SetBOTAContainer(botaBarControl);
+            regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
+            PDFGrid.Child = regularViewerControl;
+        }
+
+        private void LoadDocument()
+        {
+            if (pdfViewer.PDFView.Document == null)
+            {
+                return;
+            }
+
+            pdfViewer.PDFView.Load();
+            pdfViewer.PDFView.SetShowLink(true);
+
+            pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
+            pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
+
+            pdfViewer.PDFView.SetFormFieldHighlight(true);
+
+            PasswordUI.Closed -= PasswordUI_Closed;
+            PasswordUI.Canceled -= PasswordUI_Canceled;
+            PasswordUI.Confirmed -= PasswordUI_Confirmed;
+            PasswordUI.Closed += PasswordUI_Closed;
+            PasswordUI.Canceled += PasswordUI_Canceled;
+            PasswordUI.Confirmed += PasswordUI_Confirmed;
+            ModeComboBox.SelectedIndex = 0;
+            LoadCustomControl();
+            pdfViewer.PDFView.ChangeFitMode(FitMode.FitWidth);
+            CPDFSaclingControl.InitWithPDFViewer(pdfViewer.PDFView);
+            regularViewerControl.IsActive = true;
+        }
+
+        private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
+        {
+            if (e.Key == "Zoom")
+            {
+                CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
+            }
+        }
+
+        private void PasswordUI_Confirmed(object sender, string e)
+        {
+            if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
+            {
+                passwordViewer.PDFView.Document.UnlockWithPassword(e);
+                if (passwordViewer.PDFView.Document.IsLocked == false)
+                {
+                    PasswordUI.SetShowError("", Visibility.Collapsed);
+                    PasswordUI.ClearPassword();
+                    PasswordUI.Visibility = Visibility.Collapsed;
+                    PopupBorder.Visibility = Visibility.Collapsed;
+                    pdfViewer = passwordViewer;
+                    LoadDocument();
+                }
+                else
+                {
+                    PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
+                }
+            }
+        }
+
+        private void PasswordUI_Canceled(object sender, EventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+            PasswordUI.Visibility = Visibility.Collapsed;
         }
 
+        private void PasswordUI_Closed(object sender, EventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+            PasswordUI.Visibility = Visibility.Collapsed;
+        }
+        #endregion
+
         private void OpenFile_Click(object sender, RoutedEventArgs e)
         {
 
@@ -42,7 +204,46 @@ namespace DigitalSignature
 
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
+            var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
+            if (item.Content as string == currentMode)
+            {
+                return;
+            }
+
+            if (currentMode == "Viewer")
+            {
+                regularViewerControl.ClearViewerControl();
+                regularViewerControl.IsActive = false;
+            }
+            else if(currentMode == "Digital Signature")
+            {
+                digitalSignatureControl.ClearViewerControl();
+            }
 
+            if (item.Content as string == "Viewer")
+            {
+                regularViewerControl.IsActive = true;
+                if (regularViewerControl.PdfViewControl != null && regularViewerControl.PdfViewControl.PDFView != null)
+                {
+                    PDFGrid.Child = regularViewerControl;
+                    regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+                    regularViewerControl.PdfViewControl = pdfViewer; 
+                    regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
+                    regularViewerControl.SetBOTAContainer(botaBarControl);
+                    regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
+                }
+            }
+            else if (item.Content as string == "Digital Signature")
+            {
+                if (digitalSignatureControl.PdfViewControl != null && digitalSignatureControl.PdfViewControl.PDFView != null)
+                {
+                    PDFGrid.Child = digitalSignatureControl;
+                    digitalSignatureControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+                    digitalSignatureControl.PdfViewControl = pdfViewer;
+                    digitalSignatureControl.InitWithPDFViewer(pdfViewer.PDFView);
+                }
+            }
+            currentMode = item.Content as string;
         }
 
         private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
@@ -69,5 +270,16 @@ namespace DigitalSignature
         {
 
         }
+
+        private void Window_Loaded(object sender, RoutedEventArgs e)
+        {
+            pdfViewer = new PDFViewControl();
+            LoadDefaultDocument();
+        }
+
+        private void Window_Unloaded(object sender, RoutedEventArgs e)
+        {
+
+        }
     }
 }

+ 1 - 2
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -47,7 +47,6 @@ namespace PDFViewer
             }
         }
 
-        private bool _leftToolPanelButtonIsChecked;
         public bool LeftToolPanelButtonIsChecked
         {
             get => panelState.IsLeftPanelExpand;
@@ -206,7 +205,7 @@ namespace PDFViewer
 
         #endregion
 
-        #region Load Unload custom control
+        #region Load  custom control
         private void LoadCustomControl()
         {
             regularViewerControl.PdfViewControl = pdfViewer;