-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
81 lines (66 loc) · 3.62 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using DevExpress.Pdf;
using System.Diagnostics;
using DevExpress.Office.DigitalSignatures;
using System.Linq;
using DevExpress.Office.Tsp;
namespace PdfDocumentProcessor
{
class Program
{
static void Main(string[] args)
{
ApplySignatures();
Process.Start(new ProcessStartInfo("SignedDocument.pdf") { UseShellExecute = true });
}
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 TsaClient(new Uri(@"https://freetsa.org/tsr"), HashAlgorithmType.SHA256);
//Create a PAdES PKCS#7 signature
Pkcs7Signer pkcs7Signature = new Pkcs7Signer("Signing Documents/certificate.pfx", "123", HashAlgorithmType.SHA256, tsaClient, null, null, PdfSignatureProfile.PAdES_BES);
//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.Location = "Australia";
santuzzaSignature.Name = "Santuzza Valentina";
santuzzaSignature.Reason = "I Agree";
// Specify signature appearance parameters:
PdfSignatureAppearance signatureAppearance = new PdfSignatureAppearance();
signatureAppearance.SetImageData("Signing Documents/SantuzzaValentina.png");
signatureAppearance.SignatureDetailsFont.Size = 12;
signatureAppearance.SignatureDetailsFont.Italic = true;
signatureAppearance.ShowDate = true;
signatureAppearance.ShowReason = true;
santuzzaSignature.SetSignatureAppearance(signatureAppearance);
//Create a new signature form field:
var signatureFieldInfo1 = new PdfSignatureFieldInfo(1);
signatureFieldInfo1.Name = "SignatureField1";
signatureFieldInfo1.SignatureBounds = new PdfRectangle(200, 200, 250, 250);
//Create a document level time stamp:
PdfTimeStamp pdfTimeStamp = new PdfTimeStamp(tsaClient);
//Apply this time stamp to the form field:
var timeStampSignature = new PdfSignatureBuilder(pdfTimeStamp, signatureFieldInfo1);
//Add signatures to an array
PdfSignatureBuilder[] signatures = { cooperSignature, santuzzaSignature, timeStampSignature };
//Sign and save the document
signer.SaveDocument("SignedDocument.pdf", signatures);
}
}
}
}