-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
60 lines (49 loc) · 2.44 KB
/
Program.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
using System;
using DevExpress.Pdf;
using System.Diagnostics;
using System.Linq;
namespace PdfDocumentProcessor
{
class Program
{
static void Main(string[] args)
{
ApplySignatures();
Process.Start("SignedDocument.pdf");
}
public static void ApplySignatures()
{
//Load a document to sign
using (var signer = new PdfDocumentSigner("Document.pdf"))
{
//Specify the name and location of the signature field
var signatureFieldInfo = new PdfSignatureFieldInfo(1);
signatureFieldInfo.Name = "SignatureField";
signatureFieldInfo.SignatureBounds = new PdfRectangle(20, 20, 150, 150);
signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90;
//Create a timestamp
ITsaClient tsaClient = new PdfTsaClient(new Uri(@"https://freetsa.org/tsr"), PdfHashAlgorithm.SHA256);
//Create a PKCS#7 signature
Pkcs7Signer pkcs7Signature = new Pkcs7Signer("Signing Documents/certificate.pfx", "123", PdfHashAlgorithm.SHA256, tsaClient);
//Apply a signature to a new form field created before
var cooperSignature = new PdfSignatureBuilder(pkcs7Signature, signatureFieldInfo);
//Specify an image and signer information
cooperSignature.SetImageData(System.IO.File.ReadAllBytes("Signing Documents/JaneCooper.jpg"));
cooperSignature.Location = "USA";
cooperSignature.Name = "Jane Cooper";
cooperSignature.Reason = "Acknowledgement";
//Apply a signature to an existing form field
var santuzzaSignature = new PdfSignatureBuilder(pkcs7Signature, "Sign");
//Specify an image and signer information
santuzzaSignature.SetImageData(System.IO.File.ReadAllBytes("Signing Documents/SantuzzaValentina.jpg"));
santuzzaSignature.Location = "Australia";
santuzzaSignature.Name = "Santuzza Valentina";
santuzzaSignature.Reason = "I Agree";
//Add signatures to an array
PdfSignatureBuilder[] signatures = { cooperSignature, santuzzaSignature };
//Sign and save the document
signer.SaveDocument("SignedDocument.pdf", signatures);
}
}
}
}