Browse Source

PDFForm(Windows)-签名功能

zhuyi 1 year ago
parent
commit
94f95ffec1

+ 1 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFSignatureUI.xaml

@@ -6,6 +6,7 @@
              xmlns:local="clr-namespace:compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI"
              mc:Ignorable="d" 
              Loaded="UserControl_Loaded"
+             Unloaded="UserControl_Unloaded"
               d:DesignHeight="800" d:DesignWidth="300">
     <UserControl.Resources>
         <ResourceDictionary>

+ 53 - 5
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFSignatureUI.xaml.cs

@@ -1,5 +1,8 @@
-using compdfkit_tools.Data;
+using ComPDFKit.Import;
+using compdfkit_tools.Data;
 using compdfkit_tools.Properties;
+using ComPDFKitViewer.AnnotEvent;
+using ComPDFKitViewer.PdfViewer;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -24,11 +27,18 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
     {
         public event EventHandler<CPDFAnnotationData> PropertyChanged;
         public ObservableCollection<CPDFSignatureData> SignatureList { get; set; }
+        private WidgetSignArgs widgetSignArgs;
+        private CPDFViewer pdfViewer;
+
         public CPDFSignatureUI()
         {
             InitializeComponent();
         }
-
+        public void SetFormProperty(WidgetArgs Args, CPDFViewer cPDFViewer)
+        {
+            widgetSignArgs = (WidgetSignArgs)Args;
+            pdfViewer = cPDFViewer;
+        }
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             SignatureList = new ObservableCollection<CPDFSignatureData>();
@@ -59,7 +69,39 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 
         private void Signature_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
-            PropertyChanged?.Invoke(this, (sender as ListBoxItem).DataContext as CPDFSignatureData);
+            if (widgetSignArgs == null || pdfViewer == null)
+            {
+                PropertyChanged?.Invoke(this, (sender as ListBoxItem).DataContext as CPDFSignatureData);
+            }
+            else
+            {
+                FillForm(((sender as ListBoxItem).DataContext as CPDFSignatureData).SourcePath);
+            }
+        }
+
+        private void FillForm(string ImagePath)
+        {
+            if (!string.IsNullOrEmpty(ImagePath))
+            {
+                using (FileStream fileData = File.OpenRead(ImagePath))
+                {
+                    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);
+                        widgetSignArgs?.UpdateApWithImage(ImageArray, ImageWidth, ImageHeight, C_Scale_Type.fitCenter, 0);
+                        pdfViewer?.ReloadVisibleAnnots();
+                    }
+                }
+            }
         }
 
         private void CreateSignature_Click(object sender, RoutedEventArgs e)
@@ -101,14 +143,14 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                     {
                         CPDFDeleteDialog cPDFDeleteDialog = new CPDFDeleteDialog("Warning", "Are you sure to delete?");
                         cPDFDeleteDialog.Owner = Window.GetWindow(this);
-                        cPDFDeleteDialog.WindowStartupLocation= WindowStartupLocation.CenterOwner;
+                        cPDFDeleteDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                         cPDFDeleteDialog.ShowDialog();
                         if (!cPDFDeleteDialog.IsDelete)
                         {
                             return;
                         }
 
-                        if (data.SourcePath!=null)
+                        if (data.SourcePath != null)
                         {
                             try
                             {
@@ -136,5 +178,11 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                 }
             }
         }
+
+        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
+        {
+            widgetSignArgs = null;
+            pdfViewer = null;
+        }
     }
 }

+ 6 - 3
compdfkit_demo_windows/compdfkit/compdfkit-tools/Form/FromPropertyControl.xaml.cs

@@ -77,9 +77,12 @@ namespace compdfkit_tools.Form
                     currentPanel = listBoxProperty;
                     break;
                 case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
-                    CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
-                    //signatureProperty.SetProperty(Args, e);
-                    currentPanel = signatureProperty;
+                    if (e==null)
+                    {
+                        CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
+                        signatureProperty.SetFormProperty(Args, pdfViewer);
+                        currentPanel = signatureProperty;
+                    }
                     break;
                 case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_UNKNOWN:
                     break;

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Form/Property/ComboBoxProperty.xaml

@@ -24,7 +24,7 @@
         </Grid.RowDefinitions>
         <Border BorderThickness="0" BorderBrush="#1A000000">
             <Grid  Height="40" Background="White" >
-                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Text Field" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
+                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Combo Box" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
             </Grid>
         </Border>
         <TabControl x:Name="TopTabControl" Grid.Row="1" Style="{DynamicResource TabControlStyle1}" BorderThickness="0">

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Form/Property/ListBoxProperty.xaml

@@ -24,7 +24,7 @@
         </Grid.RowDefinitions>
         <Border BorderThickness="0" BorderBrush="#1A000000">
             <Grid  Height="40" Background="White" >
-                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Text Field" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
+                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="ListBox" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
             </Grid>
         </Border>
         <TabControl x:Name="TopTabControl" Grid.Row="1" Style="{DynamicResource TabControlStyle1}" BorderThickness="0">

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Form/Property/PushButtonProperty.xaml

@@ -41,7 +41,7 @@
         </Grid.RowDefinitions>
         <Border BorderThickness="0" BorderBrush="#1A000000">
             <Grid  Height="40" Background="White" >
-                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Text Field" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
+                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="PushButton" FontSize="14" FontFamily="Segoe UI" FontWeight="Bold"/>
             </Grid>
         </Border>
         <TabControl x:Name="TopTabControl" Grid.Row="1" Style="{DynamicResource TabControlStyle1}" BorderThickness="0">

+ 8 - 0
compdfkit_demo_windows/compdfkit/form-ctrl-demo/MainWindow.xaml.cs

@@ -802,6 +802,14 @@ namespace form_ctrl_demo
                     pdfViewControl.PDFView?.SetShowLink(false);
                     pdfViewControl.PDFView?.SetMouseMode(MouseModes.FormEditTool);
                     pdfViewControl.PDFView?.ReloadDocument();
+                    if (PropertyContainer != null)
+                    {
+                        fromPropertyControl.CleanProperty();
+                        PropertyContainer.Width = 0;
+                        PropertyContainer.Child = null;
+                        ViewSettingBtn.IsChecked = false;
+                        FormBarBtn.IsChecked = false;
+                    }
                 }
             }
         }