|
@@ -8,6 +8,7 @@ using Compdfkit_Tools.Helper;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
+using System.IO;
|
|
|
using System.Reflection;
|
|
|
using System.Runtime.Remoting.Messaging;
|
|
|
using System.Windows;
|
|
@@ -29,6 +30,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
/// </summary>
|
|
|
public partial class FillDigitalSignatureControl : UserControl
|
|
|
{
|
|
|
+
|
|
|
+ private readonly string logoPath = "Logo.png";
|
|
|
+ private string imagePath = string.Empty;
|
|
|
+ private string Text = string.Empty;
|
|
|
private Dictionary<string, Border> TabDict { get; set; }
|
|
|
|
|
|
private CPDFSignatureConfig tempSignatureConfig = new CPDFSignatureConfig();
|
|
@@ -37,13 +42,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
public CPDFDocument Document;
|
|
|
|
|
|
+ private string signatureName = string.Empty;
|
|
|
+
|
|
|
private string location = string.Empty;
|
|
|
|
|
|
private string reason = string.Empty;
|
|
|
|
|
|
private string _signaturePath = string.Empty;
|
|
|
public string SignaturePath
|
|
|
- {
|
|
|
+ {
|
|
|
get => _signaturePath;
|
|
|
set
|
|
|
{
|
|
@@ -59,16 +66,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
_password = value;
|
|
|
signatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path(SignaturePath, Password);
|
|
|
- tempSignatureConfig.Text = DictionaryValueConverter.GetGrantorFormDictionary(signatureCertificate.SubjectDict);
|
|
|
+ signatureName = DictionaryValueConverter.GetGrantorFormDictionary(signatureCertificate.SubjectDict);
|
|
|
+ tempSignatureConfig.Text = signatureName;
|
|
|
CreateTempSignature();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public CPDFSignatureWidget signatureWidget { get; set; }
|
|
|
|
|
|
- private readonly string logoPath = "Logo.png";
|
|
|
- private string imagePath = string.Empty;
|
|
|
- private string Text = string.Empty;
|
|
|
+ public event EventHandler<string> AfterFillSignature;
|
|
|
|
|
|
public FillDigitalSignatureControl()
|
|
|
{
|
|
@@ -170,23 +176,26 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
tempSignatureConfig.IsDrawOnlyContent = false;
|
|
|
if (clickBorder == KeyboardBorder)
|
|
|
- {
|
|
|
+ {
|
|
|
+ tempSignatureConfig.Text = signatureName;
|
|
|
tempSignatureConfig.ImageBitmap = null;
|
|
|
}
|
|
|
else
|
|
|
- {
|
|
|
+ {
|
|
|
+ tempSignatureConfig.Text = string.Empty;
|
|
|
if (clickBorder == TrackpadBorder)
|
|
|
{
|
|
|
CanvaDrawPopup.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
else if (clickBorder == ImageBorder)
|
|
|
{
|
|
|
+ ImagePickPanel.Visibility = Visibility.Visible;
|
|
|
if (!string.IsNullOrEmpty(imagePath))
|
|
|
{
|
|
|
tempSignatureConfig.ImageBitmap = new Bitmap(imagePath);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
SetProperty();
|
|
|
CreateTempSignature();
|
|
@@ -221,9 +230,18 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
private void CanvasClearBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
DrawInkCanvas.Strokes.Clear();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public void GetDrawInk()
|
|
|
+ private void CanvasPopupConfirm_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ tempSignatureConfig.ImageBitmap = GetDrawInk();
|
|
|
+ CanvaDrawPopup.Visibility = Visibility.Collapsed;
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Bitmap GetDrawInk()
|
|
|
{
|
|
|
if (DrawInkCanvas != null && DrawInkCanvas.Strokes != null && DrawInkCanvas.Strokes.Count > 0)
|
|
|
{
|
|
@@ -263,6 +281,18 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bound.Width, (int)bound.Height, 96, 96, PixelFormats.Pbgra32);
|
|
|
renderBitmap.Render(drawVisual);
|
|
|
+ BitmapFrame newFrame = BitmapFrame.Create(renderBitmap);
|
|
|
+ PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
|
|
|
+ pngEncoder.Frames.Add(newFrame);
|
|
|
+ using (MemoryStream newStream = new MemoryStream())
|
|
|
+ {
|
|
|
+ pngEncoder.Save(newStream);
|
|
|
+ return new Bitmap(newStream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -357,13 +387,19 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
string pngPath = CommonHelper.GetExistedPathOrEmpty("PNG files (*.png)|*.png");
|
|
|
if (!string.IsNullOrEmpty(pngPath))
|
|
|
{
|
|
|
- imagePath = CommonHelper.GetExistedPathOrEmpty(pngPath);
|
|
|
+ imagePath = pngPath;
|
|
|
+ tempSignatureConfig.ImageBitmap = new Bitmap(imagePath);
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void ClearTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
imagePath = string.Empty;
|
|
|
+ tempSignatureConfig.ImageBitmap = null;
|
|
|
+ SetProperty();
|
|
|
+ CreateTempSignature();
|
|
|
}
|
|
|
|
|
|
private void NameChk_Click(object sender, RoutedEventArgs e)
|
|
@@ -451,8 +487,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
|
|
|
private void ContinueBtn_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", Document.FileName+ "_Signed.pdf");
|
|
|
+ {
|
|
|
+ string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", Document.FileName + "_Signed.pdf");
|
|
|
|
|
|
if (string.IsNullOrEmpty(filePath))
|
|
|
{
|
|
@@ -479,7 +515,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
signatureWidget.UpdataApWithSignature(tempSignatureConfig);
|
|
|
|
|
|
- Document.WriteSignatureToFilePath(signatureWidget, filePath, SignaturePath, Password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone);
|
|
|
+ if (Document.WriteSignatureToFilePath(signatureWidget, filePath, SignaturePath, Password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
|
|
|
+ {
|
|
|
+ AfterFillSignature?.Invoke(sender, filePath);
|
|
|
+ }
|
|
|
+
|
|
|
CloseWindow(sender);
|
|
|
}
|
|
|
|