Browse Source

compdfkit(win) - Viewer和注释模块点击电子签名弹出侧边栏

weixiangjie 1 year ago
parent
commit
a495d5ac1f

+ 23 - 1
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -15,7 +15,9 @@ using System.Windows;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
 using System.Windows.Media.Imaging;
+using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
 using Compdfkit_Tools.Helper;
+using ComPDFKit.PDFAnnotation.Form;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -126,6 +128,7 @@ namespace Compdfkit_Tools.PDFControl
             PDFViewControl.PDFView = pdfViewer;
             PDFGrid.Child = PDFViewControl;
             FloatPageTool.InitWithPDFViewer(pdfViewer);
+            InitialPDFViewControl(PDFViewControl);
         }
 
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
@@ -154,12 +157,12 @@ namespace Compdfkit_Tools.PDFControl
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             InitialPDFViewControl(PDFViewControl);
-            PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
             PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
+            PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
         }
 
 
@@ -194,6 +197,11 @@ namespace Compdfkit_Tools.PDFControl
             PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
             PDFViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
             PDFViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
+            
+            PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
+            PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
+            PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
+            PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
 
         public void UnloadEvent()
@@ -687,6 +695,20 @@ namespace Compdfkit_Tools.PDFControl
             PropertyContainer.Child = PDFAnnotationControl;
             PDFAnnotationControl.SetAnnotEventData(e);
         }
+        
+        private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
+        {
+            if ((e is WidgetSignArgs))
+            {
+                if (e.WidgeType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
+                {
+                    panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
+                    CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                    signatureProperty.SetFormProperty(e, PDFViewControl.PDFView);
+                    PropertyContainer.Child = signatureProperty;
+                }
+            }
+        }
 
         private void PDFView_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {

+ 0 - 46
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml.cs

@@ -33,52 +33,6 @@ namespace Compdfkit_Tools.PDFControl
             Content = PDFView;
             PDFView.MouseWheelZoomHandler += PDFView_MouseWheelZoomHandler;
             PDFView.PDFActionHandler += PDFView_PDFActionHandler;
-            PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
-        }
-
-        /// <summary>
-        /// set CustomSignhandle = ture if dont need this default function. 
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
-        {
-            if ((e is WidgetSignArgs) && CustomSignHandle == false)
-            {
-                try
-                {
-                    WidgetSignArgs signArgs = (WidgetSignArgs)e;
-
-                    OpenFileDialog openFileDialog = new OpenFileDialog();
-                    openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
-                    if (openFileDialog.ShowDialog() == true)
-                    {
-                        string ImagePath = openFileDialog.FileName;
-                        using (FileStream fileData = File.OpenRead(ImagePath))
-                        {
-                            string fileExt = System.IO.Path.GetExtension(ImagePath).ToLower();
-                            BitmapFrame frame = null;
-                            BitmapDecoder decoder = BitmapDecoder.Create(fileData, BitmapCreateOptions.None, BitmapCacheOption.Default);
-                            if (decoder != null && decoder.Frames.Count > 0)
-                            {
-                                frame = decoder.Frames[0];
-                            }
-                            if (frame != null)
-                            {
-                                byte[] ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
-                                int ImageWidth = frame.PixelWidth;
-                                int ImageHeight = frame.PixelHeight;
-                                frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
-                                signArgs.UpdateApWithImage(ImageArray, ImageWidth, ImageHeight, C_Scale_Type.fitCenter, 0);
-                            }
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-
-                }
-            }
         }
 
         private void PDFView_PDFActionHandler(object sender, CPDFAction pdfAction)

+ 21 - 1
Demo/Examples/Compdfkit_Tools/PDFView/RegularViewerControl.xaml.cs

@@ -10,8 +10,10 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Media.Imaging;
+using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
 using Compdfkit_Tools.Helper;
 using Compdfkit_Tools.PDFControl;
+using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKitViewer;
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
@@ -122,7 +124,21 @@ namespace Compdfkit_Tools.PDFView
                 PdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
             }
         }
-        
+
+        private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
+        {
+            if ((e is WidgetSignArgs))
+            {
+                if (e.WidgeType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
+                {
+                    panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
+                    CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                    signatureProperty.SetFormProperty(e, PdfViewControl.PDFView);
+                    PropertyContainer.Child = signatureProperty;
+                }
+            }
+        }
+
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
         {
             this.BotaContainer.Child = botaControl;
@@ -355,11 +371,15 @@ namespace Compdfkit_Tools.PDFView
         {
             PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
             PdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
+            
+            PdfViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
+            PdfViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         } 
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
             PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
+            PdfViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
     }
 }