Browse Source

compdfkit(win) - 设置数字签名外观

liuaoran 1 year ago
parent
commit
0d7505899c

+ 5 - 3
Demo/Examples/Compdfkit_Tools/Common/Helper/CommonHelper.cs

@@ -12,6 +12,7 @@ using System.Runtime.CompilerServices;
 using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Interop;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Xml;
@@ -47,7 +48,8 @@ namespace Compdfkit_Tools.Helper
     }
 
     public static class CommonHelper
-    {
+    { 
+
         public static string EmailPattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
 
 
@@ -86,12 +88,12 @@ namespace Compdfkit_Tools.Helper
             }
         }
          
-        public static string GetExistedPathOrEmpty()
+        public static string GetExistedPathOrEmpty(string filter = "PDF files (*.pdf)|*.pdf")
         {
             string selectedFilePath = string.Empty;
             OpenFileDialog openFileDialog = new OpenFileDialog
             {
-                Filter = "PDF files (*.pdf)|*.pdf"
+                Filter = filter
             };
 
             if (openFileDialog.ShowDialog() == true)

+ 4 - 4
Demo/Examples/Compdfkit_Tools/DigitalSignature/AddCertificationControl/AddExistedCertificationControl.xaml

@@ -23,15 +23,15 @@
         <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10,0,0,8">
             <TextBlock Text="Files" Foreground="#43474D" FontSize="14" VerticalAlignment="Center" Margin="10,0,10,0" HorizontalAlignment="Left" Width="58" FontFamily="Segoe UI"></TextBlock>
             <Grid IsEnabled="{Binding InputEnable}">
-                <TextBox Width="258" Height="28"  x:Name="FileNameText" VerticalContentAlignment="Center" TextChanged="FileNameText_TextChanged" VerticalAlignment="Center" IsReadOnly="True"/>
-                <TextBlock Text="Select a file" Margin="8" VerticalAlignment="Center"   Visibility="{Binding ElementName=FileNameText, Path=Text, Converter={StaticResource TextLengthToVisibilityConverter}}" IsHitTestVisible="False"  Foreground="#BBB"></TextBlock>
+                <TextBox Width="258" Height="28"  x:Name="FileNameTxt" VerticalContentAlignment="Center" VerticalAlignment="Center" IsReadOnly="True"/>
+                <TextBlock Text="Select a file" Margin="8" VerticalAlignment="Center"   Visibility="{Binding ElementName=FileNameTxt, Path=Text, Converter={StaticResource TextLengthToVisibilityConverter}}" IsHitTestVisible="False"  Foreground="#BBB"></TextBlock>
             </Grid>
-            <Button Content="Select File" Width="90" Height="28" FontSize="14" FontFamily="Segoe UI" Margin="8,0,0,0"></Button>
+            <Button x:Name="SelectFileBtn" Content="Select File" Width="90" Height="28" FontSize="14" FontFamily="Segoe UI" Margin="8,0,0,0" Click="SelectFileBtn_Click"></Button>
         </StackPanel>
         <StackPanel Grid.Row="2" Orientation="Horizontal"  Margin="10,0,0,8">
             <TextBlock Foreground="#43474D" Width="58" FontSize="14" FontFamily="Segoe UI" Text="Password" VerticalAlignment="Top" Margin="10,5,10,0"></TextBlock>
             <StackPanel  Margin="0,0,0,0">
-                <PasswordBox Name="PasswordBoxText" Padding="5,0,0,0" Width="258" Height="28"  VerticalContentAlignment="Center" VerticalAlignment="Center"></PasswordBox>
+                <PasswordBox Name="PasswordBoxTxt" Padding="5,0,0,0" Width="258" Height="28"  VerticalContentAlignment="Center" VerticalAlignment="Center"></PasswordBox>
                 <TextBlock Name="ErrorTipsText" Foreground="Red" Margin="0,4,0,0" Visibility="Collapsed">Wrong password, please try again.</TextBlock>
             </StackPanel>
         </StackPanel>

+ 29 - 6
Demo/Examples/Compdfkit_Tools/DigitalSignature/AddCertificationControl/AddExistedCertificationControl.xaml.cs

@@ -1,3 +1,5 @@
+using ComPDFKit.DigitalSign;
+using Compdfkit_Tools.Helper;
 using System;
 using System.Windows.Controls;
 
@@ -12,11 +14,6 @@ namespace Compdfkit_Tools.PDFControl
             InitializeComponent();
         }
 
-        private void FileNameText_TextChanged(object sender, TextChangedEventArgs e)
-        {
-            
-        }
-
         private void CancelBtn_Click(object sender, System.Windows.RoutedEventArgs e)
         {
             CancelEvent?.Invoke(this, EventArgs.Empty);
@@ -24,7 +21,33 @@ namespace Compdfkit_Tools.PDFControl
 
         private void DoneBtn_Click(object sender, System.Windows.RoutedEventArgs e)
         {
-            SaveEvent?.Invoke(this, EventArgs.Empty);
+            if (FileNameTxt.Text == string.Empty)
+            {
+                return;
+            }
+            else if (PasswordBoxTxt.Password == string.Empty)
+            {
+                return;
+            }
+            else if(!CPDFPKCS12CertHelper.CheckPKCS12Password(FileNameTxt.Text, PasswordBoxTxt.Password))
+            {
+                return; 
+            }
+            else
+            {
+                FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog();
+                fillDigitalSignatureDialog.FilePath = FileNameTxt.Text;
+                fillDigitalSignatureDialog.ShowDialog();
+            } 
+        }
+
+        private void SelectFileBtn_Click(object sender, System.Windows.RoutedEventArgs e)
+        {
+            string filePath = CommonHelper.GetExistedPathOrEmpty("PFX Files(*.pfx) | *.pfx");
+            if (filePath != string.Empty)
+            {
+                FileNameTxt.Text = filePath;
+            }
         }
     }
 }

+ 11 - 8
Demo/Examples/Compdfkit_Tools/DigitalSignature/FillDigitalSignatureControl/FillDigitalSignatureControl.xaml.cs

@@ -5,6 +5,7 @@ using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFPage;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.IO;
 using System.Reflection;
 using System.Windows;
@@ -15,6 +16,8 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Media3D;
+using Pen = System.Windows.Media.Pen;
+using Point = System.Windows.Point;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -55,16 +58,16 @@ namespace Compdfkit_Tools.PDFControl
         private void CreateTempSignature()
         {
             CPDFDocument tempDocument = CPDFDocument.CreateDocument();
-            tempDocument.InsertPage(0, 200, 200, "");
+            tempDocument.InsertPage(0, 200, 200, string.Empty);
             CPDFPage page = tempDocument.PageAtIndex(0);
             CPDFSignatureWidget signatureWidget = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
-            signatureWidget.SetRect(new CRect(0, 100, 100, 0));
-            //signatureWidget.UpdataApWithSignature(tempSignatureConfig);
-            signatureWidget.UpdateFormAp();
-            if(signatureWidget.UpdateApWithImage("C:\\Users\\dkan\\Pictures\\Screenshots\\hao.jpg", "", 0))
-            {
-                signatureWidget.UpdateAp();
-            }
+            signatureWidget.SetRect(new CRect(0, 100, 200, 0));
+            tempSignatureConfig.IsDrawLogo = true;
+            tempSignatureConfig.LogoBitmap = new Bitmap("C:\\Users\\dkan\\Pictures\\Screenshots\\hao.jpg");
+
+            signatureWidget.UpdataApWithSignature(tempSignatureConfig);
+
+            //signatureWidget.UpdateApWithImage("C:\\Users\\dkan\\Pictures\\Screenshots\\hao.jpg", "", 0);
             byte[] signatureBitmapBytes = GetTempSignatureImage(signatureWidget, out int width, out int height);
             tempDocument.WriteToFilePath("E:\\testfile1.pdf");
 

BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.1/build/x64/ComPDFKit.dll