Browse Source

compdfkit(win) - 禁止 form 模式下签名,允许 view 与 annotation 模式下签名,其他部分代码格式调整

liuaoran 11 months ago
parent
commit
7d10409ab3

+ 38 - 8
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -21,6 +21,8 @@ using ComPDFKit.Tool;
 using PasswordBoxPlus.Helper;
 using ComPDFKit.NativeMethod;
 using ComPDFKit.PDFPage;
+using ComPDFKitViewer.Widget;
+using ComPDFKit.Tool.Help;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -31,6 +33,7 @@ namespace Compdfkit_Tools.PDFControl
         public PDFViewControl PDFViewControl;
         public CPDFAnnotationControl PDFAnnotationControl = null;
         private CPDFDisplaySettingsControl displaySettingsControl = null;
+        public FromPropertyControl FromPropertyControl = new FromPropertyControl();
 
         private PanelState panelState = PanelState.GetInstance();
 
@@ -141,6 +144,11 @@ namespace Compdfkit_Tools.PDFControl
             this.displaySettingsControl = displaySettingsControl;
         }
 
+        public void SetPropertyContainer(UIElement uiElement)
+        {
+            PropertyContainer.Child = uiElement;
+        }
+
         public void ClearAllToolState()
         {
             this.AnnotationBarControl.ClearAllToolState();
@@ -159,9 +167,31 @@ namespace Compdfkit_Tools.PDFControl
         {
             PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
             PDFViewControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
+
             InitialPDFViewControl(PDFViewControl);
         }
 
+        private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
+        {
+            if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+            {
+                BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
+                if (baseWidget != null)
+                {
+                    AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
+PDFViewControl.PDFViewTool.GetCPDFViewer().GetDocument(),
+baseWidget.GetAnnotData().PageIndex,
+baseWidget.GetAnnotData().Annot);
+                    if ((annotParam as WidgetParm).WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
+                    {
+                        CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                        signatureProperty.SetFormProperty(annotParam, PDFViewControl, baseWidget.GetAnnotData().Annot);
+                        PropertyContainer.Child = signatureProperty;
+                    } 
+                }
+            }
+        }
+
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
             PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
@@ -203,7 +233,7 @@ namespace Compdfkit_Tools.PDFControl
             //PDFViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
             //PDFViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
 
-            
+
             //PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
             //PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
@@ -262,7 +292,7 @@ namespace Compdfkit_Tools.PDFControl
                     break;
             }
         }
-        
+
         private void CreateSelectImageContextMenu(object sender, ref ContextMenu menu)
         {
             if (menu == null)
@@ -279,14 +309,14 @@ namespace Compdfkit_Tools.PDFControl
             extractImage.Click += ExtractImage_Click;
             menu.Items.Add(extractImage);
         }
-        
+
         private void ExtractImage_Click(object sender, RoutedEventArgs e)
         {
             System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
             if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
-                if(image == null)
+                if (image == null)
                 {
                     return;
                 }
@@ -304,7 +334,7 @@ namespace Compdfkit_Tools.PDFControl
         private void CopyImage_Click(object sender, RoutedEventArgs e)
         {
             var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
-            if(image == null)
+            if (image == null)
             {
                 return;
             }
@@ -320,7 +350,7 @@ namespace Compdfkit_Tools.PDFControl
                 imageData = new BitmapImage();
                 imageData.BeginInit();
                 imageData.StreamSource = ms;
-                
+
                 imageData.CacheOption = BitmapCacheOption.OnLoad;
                 imageData.EndInit();
                 imageData.Freeze();
@@ -495,14 +525,14 @@ namespace Compdfkit_Tools.PDFControl
         }
 
         private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
-        { 
+        {
             PDFAnnotationControl.LoadAnnotationPanel(e);
             if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
             {
                 panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
             }
 
-            if(e == CPDFAnnotationType.Link)
+            if (e == CPDFAnnotationType.Link)
             {
                 PDFViewControl.PDFViewTool.GetCPDFViewer().SetLinkHighlight(true);
             }

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFSignatureUI.xaml.cs

@@ -31,6 +31,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
         {
             InitializeComponent();
         }
+
         public void SetFormProperty(AnnotParam param, PDFViewControl view, CPDFAnnotation sign)
         {
             signatureParam = (SignatureParam) param;

+ 4 - 1
Demo/Examples/Compdfkit_Tools/Edit/PDFContentEditControl.xaml.cs

@@ -6,12 +6,15 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class PDFContentEditControl : UserControl
     {
+        #region  
+
         private PDFImageEditControl PDFImageEditControl = new PDFImageEditControl();
         private PDFTextEditControl PDFTextEditControl = new PDFTextEditControl();
 
         public PDFViewControl ViewControl { get; private set; }
         public PDFEditParam EditEvent { get; set; }
-
+        
+        #endregion
         public PDFContentEditControl()
         {
             InitializeComponent();

+ 1 - 10
Demo/Examples/Compdfkit_Tools/Form/FromPropertyControl.xaml.cs

@@ -62,18 +62,9 @@ namespace Compdfkit_Tools.PDFControl
                     currentPanel = listBoxProperty;
                     break;
                 case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
-                    if (pdfViewerControl.PDFToolManager.GetToolType()==CPDFToolManager.ToolType.WidgetEdit)
-                    {
-                        CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
-                        signatureProperty.SetFormProperty(annotParam, pdfViewerControl, annotation);
-                        currentPanel = signatureProperty;
-                    }
-                    else
-                    {
                         SignatureProperty signatureProperty = new SignatureProperty();
                         signatureProperty.SetProperty(annotParam, annotation, cPDFDocument, pdfViewerControl);
-                        currentPanel = signatureProperty;
-                    }
+                        currentPanel = signatureProperty; 
                     break;
                 case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_UNKNOWN:
                     break;

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Form/Property/SignatureProperty.xaml

@@ -36,7 +36,7 @@
 
             <StackPanel Grid.Column="1">
                 <TextBlock Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Visibility}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold"/>
-                <ComboBox x:Name="FormFieldCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FormFieldCmb_SelectionChanged">
+                <ComboBox x:Name="FormFieldCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FormFieldCmb_SelectionChanged" Height="32">
                     <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Option_Visible}"/>
                     <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Option_Hidden}"/>
                     <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Option_NoPrint}"/>

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

@@ -56,6 +56,11 @@ namespace Compdfkit_Tools.PDFView
             panelState.PropertyChanged += PanelState_PropertyChanged;
         }
 
+        public void SetPropertyContainer(UIElement uiElement)
+        {
+            PropertyContainer.Child = uiElement;
+        }
+
         private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
@@ -96,6 +101,8 @@ namespace Compdfkit_Tools.PDFView
             }
         }
 
+
+
         public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
         {
             PropertyContainer.Width = 260;

+ 4 - 1
Demo/Examples/Compdfkit_Tools/PageEdit/PDFPageEdit/CPDFPageEditControl.xaml.cs

@@ -59,8 +59,9 @@ namespace Compdfkit_Tools.PDFControl
                 return null;
             }
         }
-        #endregion 
+        #endregion
 
+        #region Properties
         private ObservableCollection<ListBoxItem> bindPageList = new ObservableCollection<ListBoxItem>();
         public bool isThumbInitialized = false;
         private const int THUMBNAIL_WIDTH = 150;
@@ -121,6 +122,8 @@ namespace Compdfkit_Tools.PDFControl
         public event EventHandler ExitPageEdit;
         private delegate void OnThumbnailGeneratedEventHandler(int pageIndex, byte[] thumb, int w, int h);
         private OnThumbnailGeneratedEventHandler OnThumbnailGenerated;
+        #endregion
+
         public CPDFPageEditControl()
         {
             InitializeComponent();

+ 42 - 3
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -1,10 +1,15 @@
-using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKit.PDFAnnotation.Form;
+using ComPDFKit.PDFDocument;
 using ComPDFKit.Tool;
+using ComPDFKit.Tool.Help;
+using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
 using Compdfkit_Tools.Helper;
 using Compdfkit_Tools.Measure;
 using Compdfkit_Tools.PDFControl;
 using Compdfkit_Tools.PDFView;
 using ComPDFKitViewer;
+using ComPDFKitViewer.Widget;
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
@@ -185,6 +190,40 @@ namespace PDFViewer
                 panelState.PropertyChanged += PanelState_PropertyChanged;
                 displaySettingsControl.SplitModeChanged -= DisplaySettingsControl_SplitModeChanged;
                 displaySettingsControl.SplitModeChanged += DisplaySettingsControl_SplitModeChanged;
+
+                viewControl.PDFToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
+                viewControl.PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
+            }
+        }
+
+
+        private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
+        {
+            if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+            {
+                BaseWidget baseWidget = viewControl.GetCacheHitTestWidget();
+                if (baseWidget != null)
+                {
+                    AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
+viewControl.PDFViewTool.GetCPDFViewer().GetDocument(),
+baseWidget.GetAnnotData().PageIndex,
+baseWidget.GetAnnotData().Annot);
+                    if ((annotParam as WidgetParm).WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
+                    {
+                        if (currentMode == "Annotation")
+                        {
+                            CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                            signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
+                            annotationControl.SetPropertyContainer(signatureProperty);
+                        }
+                        else if (currentMode == "Viewer")
+                        {
+                            CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                            signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
+                            regularViewerControl.SetPropertyContainer(signatureProperty);
+                        } 
+                    }
+                }
             }
         }
 
@@ -660,7 +699,7 @@ namespace PDFViewer
         {
             if (viewControl != null && viewControl.GetCPDFViewer() != null && viewControl.GetCPDFViewer().GetDocument() != null)
             {
-                string savePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", viewControl.GetCPDFViewer().GetDocument().FileName + "_Flattened.pdf");
+                string savePath = Compdfkit_Tools.Helper.CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", viewControl.GetCPDFViewer().GetDocument().FileName + "_Flattened.pdf");
                 if (!string.IsNullOrEmpty(savePath))
                 {
                     if (CanSave)
@@ -746,7 +785,7 @@ namespace PDFViewer
                 }
                 if (string.IsNullOrEmpty(filePath))
                 {
-                    filePath = CommonHelper.GetExistedPathOrEmpty();
+                    filePath = Compdfkit_Tools.Helper.CommonHelper.GetExistedPathOrEmpty();
                 }
                 string oldFilePath = pdfDoc.FilePath;