|
@@ -1,8 +1,10 @@
|
|
|
-using ComPDFKit.Import;
|
|
|
+using ComPDFKit.DigitalSign;
|
|
|
+using ComPDFKit.Import;
|
|
|
using ComPDFKit.PDFAnnotation;
|
|
|
using ComPDFKit.PDFAnnotation.Form;
|
|
|
using ComPDFKit.PDFDocument;
|
|
|
using ComPDFKit.PDFPage;
|
|
|
+using Compdfkit_Tools.Helper;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
@@ -25,11 +27,19 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
/// CPDFSignControl.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class FillDigitalSignatureControl : UserControl
|
|
|
- {
|
|
|
+ {
|
|
|
private Dictionary<string, Border> TabDict { get; set; }
|
|
|
|
|
|
private SignatureConfig tempSignatureConfig = new SignatureConfig();
|
|
|
|
|
|
+ private CPDFSignatureCertificate signatureCertificate;
|
|
|
+
|
|
|
+ public CPDFDocument Document;
|
|
|
+
|
|
|
+ private string location = string.Empty;
|
|
|
+
|
|
|
+ private string reason = string.Empty;
|
|
|
+
|
|
|
private string _filePath = string.Empty;
|
|
|
public string FilePath
|
|
|
{
|
|
@@ -40,6 +50,23 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private string _password = string.Empty;
|
|
|
+ public string Password
|
|
|
+ {
|
|
|
+ get => _password;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _password = value;
|
|
|
+ signatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path(FilePath, Password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public CPDFSignatureWidget signatureWidget { get; set; }
|
|
|
+
|
|
|
+ private readonly string logoPath = "Logo.png";
|
|
|
+ private string imagePath = string.Empty;
|
|
|
+ private string Text = string.Empty;
|
|
|
+
|
|
|
public FillDigitalSignatureControl()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -51,7 +78,6 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
["None"] = NoneBorder
|
|
|
};
|
|
|
SetCheckedTab("Keyboard");
|
|
|
-
|
|
|
CreateTempSignature();
|
|
|
}
|
|
|
|
|
@@ -61,28 +87,27 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
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, 200, 0));
|
|
|
- tempSignatureConfig.IsDrawLogo = true;
|
|
|
- tempSignatureConfig.LogoBitmap = new Bitmap("C:\\Users\\dkan\\Pictures\\Screenshots\\hao.jpg");
|
|
|
+ signatureWidget.SetRect(new CRect(0, 100, 300, 0));
|
|
|
+ tempSignatureConfig.IsDrawLogo = (bool)LogoChk.IsChecked;
|
|
|
+ tempSignatureConfig.LogoBitmap = new Bitmap(logoPath);
|
|
|
+ tempSignatureConfig.Content = Text;
|
|
|
|
|
|
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");
|
|
|
|
|
|
signatureWidget.ReleaseAnnot();
|
|
|
-
|
|
|
+
|
|
|
if (signatureBitmapBytes.Length > 0)
|
|
|
{
|
|
|
PixelFormat fmt = PixelFormats.Bgra32;
|
|
|
BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, signatureBitmapBytes, (width * fmt.BitsPerPixel + 7) / 8);
|
|
|
- imageControl.Source = bps;
|
|
|
+ imageControl.Source = bps;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
imageControl.Source = null;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static byte[] GetTempSignatureImage(CPDFSignatureWidget signatureWidget, out int width, out int height)
|
|
@@ -112,12 +137,16 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
checkBtn.IsChecked = true;
|
|
|
if (checkBtn != TextAlignLeftBtn)
|
|
|
{
|
|
|
+ tempSignatureConfig.IsContentAlginLeft = true;
|
|
|
TextAlignLeftBtn.IsChecked = false;
|
|
|
}
|
|
|
if (checkBtn != TextAlignRightBtn)
|
|
|
{
|
|
|
+ tempSignatureConfig.IsContentAlginLeft = false;
|
|
|
TextAlignRightBtn.IsChecked = false;
|
|
|
}
|
|
|
+ CreateTempSignature();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
|
|
@@ -129,15 +158,35 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
SetCheckedTab(clickBorder.Tag.ToString());
|
|
|
ImagePickPanel.Visibility = Visibility.Hidden;
|
|
|
- if (clickBorder == TrackpadBorder)
|
|
|
+
|
|
|
+ if (clickBorder == NoneBorder)
|
|
|
{
|
|
|
- CanvaDrawPopup.Visibility = Visibility.Visible;
|
|
|
+ tempSignatureConfig.IsDrawOnlyContent = true;
|
|
|
}
|
|
|
-
|
|
|
- if (clickBorder == ImageBorder)
|
|
|
+ else
|
|
|
{
|
|
|
- ImagePickPanel.Visibility = Visibility.Visible;
|
|
|
+ if (clickBorder == KeyboardBorder)
|
|
|
+ {
|
|
|
+ tempSignatureConfig.ImageBitmap = null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (clickBorder == TrackpadBorder)
|
|
|
+ {
|
|
|
+ CanvaDrawPopup.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ else if (clickBorder == ImageBorder)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(imagePath))
|
|
|
+ {
|
|
|
+ tempSignatureConfig.ImageBitmap = new Bitmap(imagePath);
|
|
|
+ }
|
|
|
+ tempSignatureConfig.Content = string.Empty;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ CreateTempSignature();
|
|
|
}
|
|
|
|
|
|
private void SetCheckedTab(string tab)
|
|
@@ -214,6 +263,81 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void SetProperty()
|
|
|
+ {
|
|
|
+ Text = string.Empty;
|
|
|
+ if ((bool)NameChk.IsChecked)
|
|
|
+ {
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "Name: ";
|
|
|
+ }
|
|
|
+ Text += DictionaryValueConverter.GetGrantorFormDictionary(signatureCertificate.SubjectDict) + "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)DateChk.IsChecked)
|
|
|
+ {
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "Date: ";
|
|
|
+ }
|
|
|
+ DateTime currentDateTime = DateTime.Now;
|
|
|
+
|
|
|
+ string customFormat = "yyyy.MM.dd HH:mm:ss";
|
|
|
+
|
|
|
+ string formattedDateTime = currentDateTime.ToString(customFormat);
|
|
|
+ Text += formattedDateTime + "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)LogoChk.IsChecked)
|
|
|
+ {
|
|
|
+ tempSignatureConfig.IsDrawLogo = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempSignatureConfig.IsDrawLogo = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)ReasonChk.IsChecked)
|
|
|
+ {
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "Reason: ";
|
|
|
+ }
|
|
|
+ Text += (ReasonCmb.SelectedItem as ComboBoxItem).Content.ToString() + "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)DistinguishableNameChk.IsChecked)
|
|
|
+ {
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "DN: ";
|
|
|
+ }
|
|
|
+ Text += DictionaryValueConverter.GetDNFromDictionary(signatureCertificate.SubjectDict) + "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)ComPDFKitVersionChk.IsChecked)
|
|
|
+ {
|
|
|
+ Assembly assembly = Assembly.GetExecutingAssembly();
|
|
|
+ Version version = assembly.GetName().Version;
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "ComPDFKit Version: ";
|
|
|
+ }
|
|
|
+ Text += version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString() + "." + version.Revision.ToString() + "\n";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)PositionChk.IsChecked)
|
|
|
+ {
|
|
|
+ if ((bool)TabChk.IsChecked)
|
|
|
+ {
|
|
|
+ Text += "Location: ";
|
|
|
+ }
|
|
|
+ Text += PositionTbx.Text + "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void ReasonCheckBox_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
CheckBox checkItem = sender as CheckBox;
|
|
@@ -224,5 +348,139 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
ReasonPanel.Visibility = checkItem.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
|
|
}
|
|
|
+
|
|
|
+ private void BrowseTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ string pngPath = CommonHelper.GetExistedPathOrEmpty("PNG files (*.png)|*.png");
|
|
|
+ if (pngPath != string.Empty)
|
|
|
+ {
|
|
|
+ imagePath = CommonHelper.GetExistedPathOrEmpty(pngPath);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ClearTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void NameChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DateChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LogoChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReasonChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (!(bool)ReasonChk.IsChecked)
|
|
|
+ {
|
|
|
+ Reasonstp.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Reasonstp.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DistinguishableNameChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PositionChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (!(bool)PositionChk.IsChecked)
|
|
|
+ {
|
|
|
+ PositionStp.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PositionStp.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TabChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReasonCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ComPDFKitVersionChk_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PositionTbx_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (!(bool)PositionChk.IsChecked)
|
|
|
+ {
|
|
|
+ PositionStp.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PositionStp.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ContinueBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf");
|
|
|
+ if (!string.IsNullOrEmpty(filePath))
|
|
|
+ {
|
|
|
+ if ((bool)ReasonChk.IsChecked)
|
|
|
+ {
|
|
|
+ reason = PositionTbx.Text;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ reason = string.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((bool)PositionChk.IsChecked)
|
|
|
+ {
|
|
|
+ location = (ReasonCmb?.SelectedItem as ComboBoxItem)?.Content?.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ location = string.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ Document.WriteSignatureToFilePath(signatureWidget, filePath, FilePath, Password, location, reason , false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CancelBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|