-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSignatureHelper.cs
73 lines (63 loc) · 2.68 KB
/
SignatureHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace iDiTect.Pdf.Demo
{
public static class SignatureHelper
{
public static void AddTextSignature2PDF()
{
//Input your certificate and password
PdfCertificate cert = new PdfCertificate("test.pfx", "iditect");
PdfSigner signer = new PdfSigner("sample.pdf", cert);
//Set signature information
signer.SignatureInfo.Contact = "123456789";
signer.SignatureInfo.Reason = "Sign by iDiTect";
signer.SignatureInfo.Location = "World Wide Web";
//Field name need to be unique in the same pdf document
signer.SignatureInfo.FieldName = "iDiTect Sign Field";
//Sign in target page
signer.SignatureInfo.PageId = 0;
//Sign in target area
signer.SignatureInfo.Rect = new Rectangle(50, 100, 150, 50);
signer.SignatureAlgorithm = SignatureAlgorithm.SHA256;
signer.SignatureType = SignatureType.Text;
signer.Sign("signed.pdf");
}
public static void AddImageSignature2PDF()
{
//Input your certificate and password
PdfCertificate cert = new PdfCertificate("test.pfx", "iditect");
PdfSigner signer = new PdfSigner("sample.pdf", cert);
//Support commonly used image format, like jpg, png, gif
signer.SignatureImageFile = "sample.jpg";
//Field name need to be unique in the same pdf document
signer.SignatureInfo.FieldName = "iDiTect Sign";
//Sign in target page
signer.SignatureInfo.PageId = 0;
//Sign in target area
signer.SignatureInfo.Rect = new Rectangle(50, 100, 100, 50);
signer.SignatureAlgorithm = SignatureAlgorithm.SHA256;
signer.SignatureType = SignatureType.Image;
signer.Sign("signed.pdf");
}
public static void CheckPDF()
{
List<SignatureInfo> infos = PdfSigner.DetectSignature("signed.pdf");
foreach (SignatureInfo info in infos)
{
Console.WriteLine(info.Contact);
Console.WriteLine(info.DigitalSigner);
Console.WriteLine(info.FieldName);
Console.WriteLine(info.Location);
Console.WriteLine(info.PageId);
Console.WriteLine(info.Reason);
Console.WriteLine(info.Rect.X + "-" + info.Rect.Y + "-" + info.Rect.Width + "-" + info.Rect.Height);
Console.WriteLine(info.SignDate);
}
Console.ReadLine();
}
}
}