ソースを参照

compdfkit(win) - 数字签名项目调整

weixiangjie 9 ヶ月 前
コミット
18d2be7b1b

+ 68 - 10
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -10,9 +10,12 @@ using System.Windows.Input;
 using System.Windows.Media;
 using Compdfkit_Tools.Helper;
 using ComPDFKit.DigitalSign;
+using ComPDFKit.PDFAnnotation;
 using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKit.Tool;
+using ComPDFKit.Tool.Help;
 using ComPDFKitViewer;
+using ComPDFKitViewer.Widget;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -141,10 +144,57 @@ namespace Compdfkit_Tools.PDFControl
             //PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
             //PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
             
+            PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
+            PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler += PDFViewControl_MouseLeftButtonDownHandler;
+            
+            
             panelState.PropertyChanged -= PanelState_PropertyChanged;
             panelState.PropertyChanged += PanelState_PropertyChanged;
         }
-        
+
+        private void PDFViewControl_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
+        {
+            if (e.annotType== C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+            {
+                BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
+                if(baseWidget == null)
+                {
+                    return;
+                }
+
+                var widget = baseWidget.GetAnnotData().Annot as CPDFWidget;
+                if (widget == null)
+                {
+                    return;
+                }
+                switch (widget.WidgetType)
+                {
+                    case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
+                        var signatureWidget = widget as CPDFSignatureWidget;
+                        CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.GetCPDFViewer().GetDocument());
+                        if (signatureWidget.IsSigned() && sig != null && sig?.SignerList.Count > 0)
+                        {
+                            ViewSignatureEvent(sender, sig);
+                        }
+                        else
+                        {
+                            Window parentWindow = Window.GetWindow((DependencyObject)sender);
+                            AddCertificationDialog addCertificationControl = new AddCertificationDialog
+                            {
+                                Owner = parentWindow
+                            };
+                            currentSignatureWidget = signatureWidget;
+                            addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
+                            addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
+                            addCertificationControl.ShowDialog();
+                        }
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+
         /// <summary>
         /// Separately, init PDFView and load undo manager event. Only use for ensuring SaveBtn is enabled after deleting digital signature on Viewer mode.
         /// </summary>
@@ -257,14 +307,22 @@ namespace Compdfkit_Tools.PDFControl
         /// </summary>
         private void CreateSign()
         {
-            //PDFViewControl.PDFView.SetMouseMode(MouseModes.FormEditTool);
-            //WidgetSignArgs signArgs = new WidgetSignArgs
-            //{
-            //    LineWidth = 1,
-            //    LineColor = Colors.Black,
-            //    FieldName = "Signature" + GetTime()
-            //};
-            //PDFViewControl.PDFView.SetToolParam(signArgs);
+            PDFViewControl.PDFToolManager.SetToolType(CPDFToolManager.ToolType.WidgetEdit);
+            PDFViewControl.SetCreateWidgetType(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS);
+            
+            SignatureParam signatureParam = new SignatureParam
+            {
+                FieldName = "Signature" + GetTime(),
+                CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET,
+                WidgetType = C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS,
+                LineWidth = 1,
+                FontName = "Helvetica",
+                LineColor =new byte[] {0,0,0 },
+                FontColor = new byte[] { 0, 0, 0 },
+                Transparency = 255,
+                HasLineColor = true,
+            };
+            PDFViewControl.SetAnnotParam(signatureParam);
         }
         
         /// <summary>
@@ -342,7 +400,7 @@ namespace Compdfkit_Tools.PDFControl
                 FilePath = e.filePath,
                 Password = e.password,
                 SignatureWidget = currentSignatureWidget,
-                //Document = PDFViewControl.PDFView.Document,
+                Document = PDFViewControl.GetCPDFViewer().GetDocument(),
                 Owner = Window.GetWindow(this)
             };
             fillDigitalSignatureDialog.AfterFillSignature -= FillDigitalSignatureDialog_AfterFillSignature; ;

+ 2 - 2
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -136,7 +136,7 @@ namespace Compdfkit_Tools.PDFControl
                 if (baseWidget != null)
                 {
                     CPDFWidget  widget =(baseWidget as CPDFWidget);
-                    switch (widget.WidgeType)
+                    switch (widget.WidgetType)
                     {
                         case C_WIDGET_TYPE.WIDGET_NONE:
                             break;
@@ -178,7 +178,7 @@ namespace Compdfkit_Tools.PDFControl
                 BaseWidget baseWidget = PdfViewControl.GetCacheHitTestWidget();
                 if (baseWidget!=null)
                 {
-                    switch ((baseWidget.GetAnnotData().Annot as CPDFWidget).WidgeType)
+                    switch ((baseWidget.GetAnnotData().Annot as CPDFWidget).WidgetType)
                     {
                         case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
                         case C_WIDGET_TYPE.WIDGET_COMBOBOX:

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Form/Property/RadioButtonProperty.xaml.cs

@@ -66,7 +66,7 @@ namespace Compdfkit_Tools.PDFControl
             if (annotList != null && annotList.Count > 0)
             {
                 count = annotList.Where(x => x.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
-                    .Cast<CPDFWidget>().Where(x => x.WidgeType == C_WIDGET_TYPE.WIDGET_RADIOBUTTON).Count();
+                    .Cast<CPDFWidget>().Where(x => x.WidgetType == C_WIDGET_TYPE.WIDGET_RADIOBUTTON).Count();
             }
 
             return count>1;

+ 0 - 3
Demo/Examples/Compdfkit_Tools/PDFView/RegularViewerControl.xaml.cs

@@ -8,11 +8,8 @@ using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
 using Compdfkit_Tools.Common;
 using Compdfkit_Tools.Helper;
 using Compdfkit_Tools.PDFControl;
-using ComPDFKit.DigitalSign;
-using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKitViewer;
 using ComPDFKit.Tool;
-using ComPDFKit.PDFAnnotation;
 
 namespace Compdfkit_Tools.PDFView
 {

ファイルの差分が大きいため隠しています
+ 3 - 2
Demo/Examples/DigitalSignature/App.xaml.cs


+ 45 - 45
Demo/Examples/DigitalSignature/MainWindow.xaml.cs

@@ -3,7 +3,6 @@ using Compdfkit_Tools.Helper;
 using Compdfkit_Tools.PDFControl;
 using Compdfkit_Tools.PDFView;
 using ComPDFKitViewer;
-using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
@@ -23,6 +22,7 @@ using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 using ComPDFKit.DigitalSign;
+using ComPDFKit.Tool;
 
 namespace DigitalSignature
 {
@@ -49,7 +49,7 @@ namespace DigitalSignature
         /// <summary>
         /// Whether the save operation can be performed.
         /// </summary>
-        private bool _canSave = false;
+        private bool _canSave = true;
         public bool CanSave
         {
             get => _canSave;
@@ -128,11 +128,11 @@ namespace DigitalSignature
             {
                 filePath = CommonHelper.GetExistedPathOrEmpty();
             }
-            string oldFilePath = pdfViewer.PDFView.Document.FilePath;
+            string oldFilePath = pdfViewer.GetCPDFViewer().GetDocument().FilePath;
 
             if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)
             {
-                if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+                if (pdfViewer.GetCPDFViewer() != null && pdfViewer.GetCPDFViewer().GetDocument() != null)
                 {
                     if (oldFilePath.ToLower() == filePath.ToLower())
                     {
@@ -141,14 +141,14 @@ namespace DigitalSignature
                 }
 
                 passwordViewer = new PDFViewControl();
-                passwordViewer.PDFView.InitDocument(filePath);
-                if (passwordViewer.PDFView.Document == null)
+                passwordViewer.InitDocument(filePath);
+                if (passwordViewer.GetCPDFViewer().GetDocument() == null)
                 {
                     MessageBox.Show("Open File Failed");
                     return;
                 }
 
-                if (passwordViewer.PDFView.Document.IsLocked)
+                if (passwordViewer.GetCPDFViewer().GetDocument().IsLocked)
                 {
                     PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " " + LanguageHelper.CommonManager.GetString("Tip_Encrypted"));
                     PasswordUI.ClearPassword();
@@ -157,7 +157,7 @@ namespace DigitalSignature
                 }
                 else
                 {
-                    pdfViewer.PDFView.Document.Release();
+                    pdfViewer.GetCPDFViewer().GetDocument().Release();
                     pdfViewer = passwordViewer;
                     LoadDocument();
                 }
@@ -170,7 +170,7 @@ namespace DigitalSignature
         private void LoadDefaultDocument()
         {
             string defaultFilePath = "ComPDFKit_Signatures_Sample_File.pdf";
-            pdfViewer.PDFView.InitDocument(defaultFilePath);
+            pdfViewer.InitDocument(defaultFilePath);
             LoadDocument();
         }
 
@@ -180,14 +180,14 @@ namespace DigitalSignature
         private void LoadCustomControl()
         {
             regularViewerControl.PdfViewControl = pdfViewer;
-            regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
-            regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+            regularViewerControl.InitWithPDFViewer(pdfViewer);
+            regularViewerControl.PdfViewControl.PDFViewTool.SetViewerModel(MouseModes.Viewer);
             regularViewerControl.SetBOTAContainer(null);
             regularViewerControl.SetBOTAContainer(botaBarControl);
             regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
             PDFGrid.Child = regularViewerControl;
             
-            SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
+            SignatureHelper.InitEffectiveSignatureList(pdfViewer.GetCPDFViewer().GetDocument());
             digitalSignatureControl.OnCanSaveChanged -= DigitalSignatureControl_OnCanSaveChanged;
             digitalSignatureControl.OnCanSaveChanged += DigitalSignatureControl_OnCanSaveChanged;
             digitalSignatureControl.SignatureStatusChanged -= DigitalSignatureControl_OnSignatureStatusChanged;
@@ -195,8 +195,8 @@ namespace DigitalSignature
             signatureStatusBarControl.OnViewSignatureButtonClicked -= ViewAllSignatures;
             signatureStatusBarControl.OnViewSignatureButtonClicked += ViewAllSignatures;
             
-            SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
-            digitalSignatureControl.LoadUndoManagerEvent(pdfViewer.PDFView);
+            SignatureHelper.VerifySignatureList(pdfViewer.GetCPDFViewer().GetDocument());
+            digitalSignatureControl.LoadUndoManagerEvent(pdfViewer.GetCPDFViewer());
             signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
             regularViewerControl.SetSignatureStatusBarControl(signatureStatusBarControl);
         }
@@ -206,18 +206,18 @@ namespace DigitalSignature
         /// </summary>
         private void LoadDocument()
         {
-            if (pdfViewer.PDFView.Document == null)
+            if (pdfViewer.GetCPDFViewer().GetDocument() == null)
             {
                 return;
             }
 
-            pdfViewer.PDFView.Load();
-            pdfViewer.PDFView.SetShowLink(true);
-
-            pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
-            pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
-
-            pdfViewer.PDFView.SetFormFieldHighlight(true);
+            // pdfViewer.PDFView.Load();
+            // pdfViewer.PDFView.SetShowLink(true);
+            //
+            // pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
+            // pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
+            //
+            // pdfViewer.PDFView.SetFormFieldHighlight(true);
             pdfViewer.CustomSignHandle = true;
 
             PasswordUI.Closed -= PasswordUI_Closed;
@@ -227,7 +227,7 @@ namespace DigitalSignature
             PasswordUI.Canceled += PasswordUI_Canceled;
             PasswordUI.Confirmed += PasswordUI_Confirmed;
             ModeComboBox.SelectedIndex = 0;
-            botaBarControl.InitWithPDFViewer(pdfViewer.PDFView);
+            botaBarControl.InitWithPDFViewer(pdfViewer);
             botaBarControl.AddBOTAContent(new []{BOTATools.Thumbnail , BOTATools.Outline , BOTATools.Bookmark , BOTATools.Search , BOTATools.Annotation , BOTATools.Signature});
             botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
             botaBarControl.DeleteSignatureEvent -= BotaControlOnDeleteSignatureEvent;
@@ -237,10 +237,10 @@ namespace DigitalSignature
             botaBarControl.ViewSignatureEvent -= digitalSignatureControl.ViewSignatureEvent;    
             botaBarControl.ViewSignatureEvent += digitalSignatureControl.ViewSignatureEvent;
             
-            displaySettingsControl.InitWithPDFViewer(pdfViewer.PDFView);
+            displaySettingsControl.InitWithPDFViewer(pdfViewer);
             LoadCustomControl();
-            pdfViewer.PDFView.ChangeFitMode(FitMode.FitWidth);
-            CPDFSaclingControl.InitWithPDFViewer(pdfViewer.PDFView);
+            pdfViewer.GetCPDFViewer().SetFitMode(FitMode.FitWidth);
+            CPDFSaclingControl.InitWithPDFViewer(pdfViewer);
             
             panelState.PropertyChanged -= PanelState_PropertyChanged;
             panelState.PropertyChanged += PanelState_PropertyChanged;
@@ -253,10 +253,10 @@ namespace DigitalSignature
         /// <param name="e"></param>
         private void PasswordUI_Confirmed(object sender, string e)
         {
-            if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
+            if (passwordViewer != null && passwordViewer.GetCPDFViewer() != null && passwordViewer.GetCPDFViewer().GetDocument() != null)
             {
-                passwordViewer.PDFView.Document.UnlockWithPassword(e);
-                if (passwordViewer.PDFView.Document.IsLocked == false)
+                passwordViewer.GetCPDFViewer().GetDocument().UnlockWithPassword(e);
+                if (passwordViewer.GetCPDFViewer().GetDocument().IsLocked == false)
                 {
                     PasswordUI.SetShowError("", Visibility.Collapsed);
                     PasswordUI.ClearPassword();
@@ -338,9 +338,8 @@ namespace DigitalSignature
         /// <param name="e"></param>
         private void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
         {
-            pdfViewer.PDFView.UndoManager.CanSave = true;
+            pdfViewer.PDFViewTool.IsDocumentModified = true;
             DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
-            //this.CanSave = true;
         }
         
         /// <summary>
@@ -350,8 +349,8 @@ namespace DigitalSignature
         /// <param name="e"></param>
         private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
         {
-            SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
-            SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
+            SignatureHelper.InitEffectiveSignatureList(pdfViewer.GetCPDFViewer().GetDocument());
+            SignatureHelper.VerifySignatureList(pdfViewer.GetCPDFViewer().GetDocument());
             signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
             botaBarControl.LoadSignatureList();
         }
@@ -387,7 +386,7 @@ namespace DigitalSignature
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
-            pdfViewer.PDFView.UndoManager.CanSave = false;
+            pdfViewer.PDFViewTool.IsDocumentModified = false;
         }
 
         /// <summary>
@@ -429,12 +428,12 @@ namespace DigitalSignature
 
             if (item.Content as string == "Viewer")
             {
-                if (regularViewerControl.PdfViewControl != null && regularViewerControl.PdfViewControl.PDFView != null)
+                if (regularViewerControl.PdfViewControl != null)
                 {
                     PDFGrid.Child = regularViewerControl;
-                    regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+                    regularViewerControl.PdfViewControl.PDFViewTool.SetViewerModel(MouseModes.Viewer);
                     regularViewerControl.PdfViewControl = pdfViewer;
-                    regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
+                    regularViewerControl.InitWithPDFViewer(pdfViewer);
                     regularViewerControl.SetBOTAContainer(botaBarControl);
                     regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
                     regularViewerControl.SetSignatureStatusBarControl(signatureStatusBarControl);
@@ -442,15 +441,16 @@ namespace DigitalSignature
             }
             else if (item.Content as string == "Digital Signature")
             {
-                if (digitalSignatureControl.PDFViewControl != null && digitalSignatureControl.PDFViewControl.PDFView != null)
+                if (digitalSignatureControl.PDFViewControl != null)
                 {
                     PDFGrid.Child = digitalSignatureControl;
-                    digitalSignatureControl.PDFViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+                    digitalSignatureControl.PDFViewControl.PDFViewTool.SetViewerModel(MouseModes.Viewer);
                     digitalSignatureControl.PDFViewControl = pdfViewer;
-                    digitalSignatureControl.InitWithPDFViewer(pdfViewer.PDFView);
+                    digitalSignatureControl.InitWithPDFViewer(pdfViewer);
                     digitalSignatureControl.SetBOTAContainer(botaBarControl);
                     digitalSignatureControl.SetDisplaySettingsControl(displaySettingsControl);
                     digitalSignatureControl.SetSignatureStatusBarControl(signatureStatusBarControl);
+                    pdfViewer.PDFViewTool.SetViewerModel(MouseModes.PanTool);
                 }
             }
             currentMode = item.Content as string;
@@ -521,7 +521,7 @@ namespace DigitalSignature
         {
             PasswordUI.Visibility = Visibility.Collapsed;
             FileInfoUI.Visibility = Visibility.Visible;
-            FileInfoControl.InitWithPDFViewer(pdfViewer.PDFView);
+            FileInfoControl.InitWithPDFViewer(pdfViewer);
             PopupBorder.Visibility = Visibility.Visible;
 
         }
@@ -593,9 +593,9 @@ namespace DigitalSignature
         public void SaveAsFile()
         {
             {
-                if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+                if (pdfViewer != null && pdfViewer.GetCPDFViewer() != null && pdfViewer.GetCPDFViewer().GetDocument() != null)
                 {
-                    CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
+                    CPDFDocument pdfDoc = pdfViewer.GetCPDFViewer().GetDocument();
                     SaveFileDialog saveDialog = new SaveFileDialog();
                     saveDialog.Filter = "(*.pdf)|*.pdf";
                     saveDialog.DefaultExt = ".pdf";
@@ -614,11 +614,11 @@ namespace DigitalSignature
         /// </summary>
         public void SaveFile()
         {
-            if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+            if (pdfViewer != null && pdfViewer.GetCPDFViewer() != null && pdfViewer.GetCPDFViewer().GetDocument() != null)
             {
                 try
                 {
-                    CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
+                    CPDFDocument pdfDoc = pdfViewer.GetCPDFViewer().GetDocument();
                     if (pdfDoc.WriteToLoadedPath())
                     {
                         return;