-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
63 lines (60 loc) · 3.58 KB
/
Program.vb
File metadata and controls
63 lines (60 loc) · 3.58 KB
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
Imports System
Imports DevExpress.Pdf
Imports System.Diagnostics
Imports DevExpress.Office.DigitalSignatures
Imports DevExpress.Office.Tsp
Namespace PdfDocumentProcessor
Friend Class Program
Shared Sub Main(ByVal args As String())
Call ApplySignatures()
Call Process.Start(New ProcessStartInfo("SignedDocument.pdf") With {.UseShellExecute = True})
End Sub
Public Shared Sub ApplySignatures()
'Load a document to sign
Using signer = New PdfDocumentSigner("Document.pdf")
'Specify the name and location of the signature field
Dim signatureFieldInfo = New PdfSignatureFieldInfo(1)
signatureFieldInfo.Name = "SignatureField"
signatureFieldInfo.SignatureBounds = New PdfRectangle(20, 20, 150, 150)
signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90
'Create a timestamp
Dim tsaClient As ITsaClient = New TsaClient(New Uri("https://freetsa.org/tsr"), HashAlgorithmType.SHA256)
'Create a PAdES PKCS#7 signature
Dim pkcs7Signature As Pkcs7Signer = New Pkcs7Signer("Signing Documents/certificate.pfx", "123", HashAlgorithmType.SHA256, tsaClient, Nothing, Nothing, PdfSignatureProfile.PAdES_BES)
'Apply a signature to a new form field created before
Dim cooperSignature = New PdfSignatureBuilder(pkcs7Signature, signatureFieldInfo)
'Specify an image and signer information
cooperSignature.SetImageData(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
Dim 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:
Dim signatureAppearance As PdfSignatureAppearance = 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:
Dim signatureFieldInfo1 = New PdfSignatureFieldInfo(1)
signatureFieldInfo1.Name = "SignatureField1"
signatureFieldInfo1.SignatureBounds = New PdfRectangle(200, 200, 250, 250)
'Create a document level time stamp:
Dim pdfTimeStamp As PdfTimeStamp = New PdfTimeStamp(tsaClient)
'Apply this time stamp to the form field:
Dim timeStampSignature = New PdfSignatureBuilder(pdfTimeStamp, signatureFieldInfo1)
'Add signatures to an array
Dim signatures As PdfSignatureBuilder() = {cooperSignature, santuzzaSignature, timeStampSignature}
'Sign and save the document
signer.SaveDocument("SignedDocument.pdf", signatures)
End Using
End Sub
End Class
End Namespace