|
@@ -1,5 +1,12 @@
|
|
|
-using System.Collections.Generic;
|
|
|
+using ComPDFKit.Import;
|
|
|
+using ComPDFKit.PDFAnnotation;
|
|
|
+using ComPDFKit.PDFAnnotation.Form;
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using System.Reflection;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Controls.Primitives;
|
|
@@ -7,6 +14,7 @@ using System.Windows.Ink;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
+using System.Windows.Media.Media3D;
|
|
|
|
|
|
namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
@@ -15,29 +23,93 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
/// </summary>
|
|
|
public partial class FillDigitalSignatureControl : UserControl
|
|
|
{
|
|
|
- private Dictionary<string,Border> TabDict { get; set; }
|
|
|
+ private Dictionary<string, Border> TabDict { get; set; }
|
|
|
+
|
|
|
+ private SignatureConfig tempSignatureConfig = new SignatureConfig();
|
|
|
+
|
|
|
+ private string _filePath = string.Empty;
|
|
|
+ public string FilePath
|
|
|
+ {
|
|
|
+ get => _filePath;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _filePath = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public FillDigitalSignatureControl()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- TabDict=new Dictionary<string,Border>();
|
|
|
- TabDict["Keyboard"] = KeyboardBorder;
|
|
|
- TabDict["Trackpad"] = TrackpadBorder;
|
|
|
- TabDict["Image"] = ImageBorder;
|
|
|
- TabDict["None"] = NoneBorder;
|
|
|
+ TabDict = new Dictionary<string, Border>
|
|
|
+ {
|
|
|
+ ["Keyboard"] = KeyboardBorder,
|
|
|
+ ["Trackpad"] = TrackpadBorder,
|
|
|
+ ["Image"] = ImageBorder,
|
|
|
+ ["None"] = NoneBorder
|
|
|
+ };
|
|
|
SetCheckedTab("Keyboard");
|
|
|
+
|
|
|
+ CreateTempSignature();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateTempSignature()
|
|
|
+ {
|
|
|
+ CPDFDocument tempDocument = CPDFDocument.CreateDocument();
|
|
|
+ tempDocument.InsertPage(0, 200, 200, null);
|
|
|
+ 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();
|
|
|
+ //}
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ imageControl.Source = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] GetTempSignatureImage(CPDFSignatureWidget signatureWidget, out int width, out int height)
|
|
|
+ {
|
|
|
+ CRect rect = signatureWidget.GetRect();
|
|
|
+
|
|
|
+ var flags = BindingFlags.NonPublic | BindingFlags.Static;
|
|
|
+ var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
|
|
|
+ int dpi = (int)dpiProperty.GetValue(null, null);
|
|
|
+
|
|
|
+ width = (int)(rect.width() * dpi / 72D * 2);
|
|
|
+ height = (int)(rect.height() * dpi / 72D * 2);
|
|
|
+
|
|
|
+ byte[] imageData = new byte[width * height * 4];
|
|
|
+ signatureWidget.RenderAnnot(width, height, imageData, CPDFAppearanceType.Normal);
|
|
|
+
|
|
|
+ return imageData;
|
|
|
}
|
|
|
|
|
|
private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- ToggleButton checkBtn=sender as ToggleButton;
|
|
|
- if(checkBtn == null)
|
|
|
+ ToggleButton checkBtn = sender as ToggleButton;
|
|
|
+ if (checkBtn == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
checkBtn.IsChecked = true;
|
|
|
- if(checkBtn!= TextAlignLeftBtn)
|
|
|
+ if (checkBtn != TextAlignLeftBtn)
|
|
|
{
|
|
|
- TextAlignLeftBtn.IsChecked= false;
|
|
|
+ TextAlignLeftBtn.IsChecked = false;
|
|
|
}
|
|
|
if (checkBtn != TextAlignRightBtn)
|
|
|
{
|
|
@@ -48,18 +120,18 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
Border clickBorder = sender as Border;
|
|
|
- if(clickBorder == null || clickBorder.Tag==null)
|
|
|
+ if (clickBorder == null || clickBorder.Tag == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
SetCheckedTab(clickBorder.Tag.ToString());
|
|
|
ImagePickPanel.Visibility = Visibility.Hidden;
|
|
|
- if (clickBorder== TrackpadBorder)
|
|
|
+ if (clickBorder == TrackpadBorder)
|
|
|
{
|
|
|
CanvaDrawPopup.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
|
|
|
- if(clickBorder== ImageBorder)
|
|
|
+ if (clickBorder == ImageBorder)
|
|
|
{
|
|
|
ImagePickPanel.Visibility = Visibility.Visible;
|
|
|
}
|
|
@@ -72,13 +144,13 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
foreach (string key in TabDict.Keys)
|
|
|
{
|
|
|
Border checkBorder = TabDict[key];
|
|
|
- if(checkBorder == null)
|
|
|
+ if (checkBorder == null)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
checkBorder.BorderThickness = new Thickness(0);
|
|
|
- if(key==tab)
|
|
|
+ if (key == tab)
|
|
|
{
|
|
|
checkBorder.BorderThickness = new Thickness(0, 0, 0, 2);
|
|
|
}
|
|
@@ -100,9 +172,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
if (DrawInkCanvas != null && DrawInkCanvas.Strokes != null && DrawInkCanvas.Strokes.Count > 0)
|
|
|
{
|
|
|
- Rect bound= DrawInkCanvas.Strokes.GetBounds();
|
|
|
+ Rect bound = DrawInkCanvas.Strokes.GetBounds();
|
|
|
DrawingVisual drawVisual = new DrawingVisual();
|
|
|
- DrawingContext drawContext= drawVisual.RenderOpen();
|
|
|
+ DrawingContext drawContext = drawVisual.RenderOpen();
|
|
|
|
|
|
foreach (Stroke drawStroke in DrawInkCanvas.Strokes)
|
|
|
{
|
|
@@ -113,11 +185,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
Figures.Add(AddFigure);
|
|
|
drawPath.Figures = Figures;
|
|
|
|
|
|
- if(drawStroke.StylusPoints.Count>1)
|
|
|
+ if (drawStroke.StylusPoints.Count > 1)
|
|
|
{
|
|
|
- StylusPoint startPoint= drawStroke.StylusPoints[0];
|
|
|
- AddFigure.StartPoint= new Point(startPoint.X - bound.X, startPoint.Y - bound.Y);
|
|
|
- for (int i = 1;i< drawStroke.StylusPoints.Count;i++)
|
|
|
+ StylusPoint startPoint = drawStroke.StylusPoints[0];
|
|
|
+ AddFigure.StartPoint = new Point(startPoint.X - bound.X, startPoint.Y - bound.Y);
|
|
|
+ for (int i = 1; i < drawStroke.StylusPoints.Count; i++)
|
|
|
{
|
|
|
StylusPoint drawPoint = drawStroke.StylusPoints[i];
|
|
|
Point offsetPoint = new Point(drawPoint.X - bound.X, drawPoint.Y - bound.Y);
|
|
@@ -127,14 +199,14 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(AddFigure.Segments.Count > 0)
|
|
|
+ if (AddFigure.Segments.Count > 0)
|
|
|
{
|
|
|
drawContext.DrawGeometry(null, drawPen, drawPath);
|
|
|
}
|
|
|
}
|
|
|
drawContext.Close();
|
|
|
|
|
|
- RenderTargetBitmap renderBitmap=new RenderTargetBitmap((int)bound.Width,(int)bound.Height,96,96,PixelFormats.Pbgra32);
|
|
|
+ RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bound.Width, (int)bound.Height, 96, 96, PixelFormats.Pbgra32);
|
|
|
renderBitmap.Render(drawVisual);
|
|
|
}
|
|
|
}
|
|
@@ -147,7 +219,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ReasonPanel.Visibility=checkItem.IsChecked==true? Visibility.Visible: Visibility.Collapsed;
|
|
|
+ ReasonPanel.Visibility = checkItem.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
|
|
|
}
|
|
|
}
|
|
|
}
|