-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
40 lines (34 loc) · 1.54 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
using DevExpress.Pdf;
using System;
using System.Diagnostics;
using DevExpress.Office.Tsp;
using DevExpress.Office.DigitalSignatures;
namespace CustomSigner
{
static class Program
{
static void Main(string[] args)
{
using (var signer = new PdfDocumentSigner(@"Document.pdf"))
{
//Create a timestamp:
ITsaClient tsaClient = new TsaClient(new Uri(@"https://freetsa.org/tsr"), HashAlgorithmType.SHA256);
//Specify the signature's field name and location:
var description = new PdfSignatureFieldInfo(1);
description.Name = "SignatureField";
description.SignatureBounds = new PdfRectangle(10, 10, 50, 150);
//Create a custom signer object:
var bouncyCastleSigner = new BouncyCastleSigner("certificate.pfx", "123", tsaClient);
//Apply a signature to a new form field:
var signatureBuilder = new PdfSignatureBuilder(bouncyCastleSigner, description);
//Specify the image and signer information:
signatureBuilder.SetImageData(System.IO.File.ReadAllBytes("signature.jpg"));
signatureBuilder.Location = "LOCATION";
//Sign and save the document:
signer.SaveDocument("SignedDocument.pdf", signatureBuilder);
Process.Start(new ProcessStartInfo("SignedDocument.pdf") { UseShellExecute = true}) ;
}
return;
}
}
}