|
1 | | -Imports System |
| 1 | +Imports System |
2 | 2 | Imports DevExpress.Pdf |
3 | 3 | Imports System.Diagnostics |
4 | 4 | Imports DevExpress.Office.DigitalSignatures |
5 | | -Imports System.Linq |
6 | 5 | Imports DevExpress.Office.Tsp |
7 | 6 |
|
8 | 7 | Namespace PdfDocumentProcessor |
9 | | - Friend Class Program |
10 | | - Shared Sub Main(ByVal args() As String) |
11 | | - ApplySignatures() |
12 | | - Process.Start("SignedDocument.pdf") |
13 | | - End Sub |
14 | 8 |
|
15 | | - Public Shared Sub ApplySignatures() |
16 | | - 'Load a document to sign |
17 | | - Using signer = New PdfDocumentSigner("Document.pdf") |
18 | | - 'Specify the name and location of the signature field |
19 | | - Dim signatureFieldInfo = New PdfSignatureFieldInfo(1) |
20 | | - signatureFieldInfo.Name = "SignatureField" |
21 | | - signatureFieldInfo.SignatureBounds = New PdfRectangle(20, 20, 150, 150) |
22 | | - signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90 |
| 9 | + Friend Class Program |
23 | 10 |
|
24 | | - 'Create a timestamp |
25 | | - Dim tsaClient As ITsaClient = New TsaClient(New Uri("https://freetsa.org/tsr"), HashAlgorithmType.SHA256) |
| 11 | + Shared Sub Main(ByVal args As String()) |
| 12 | + Call ApplySignatures() |
| 13 | + Call Process.Start("SignedDocument.pdf") |
| 14 | + End Sub |
26 | 15 |
|
27 | | - 'Create a PAdES PKCS#7 signature |
28 | | - Dim pkcs7Signature As New Pkcs7Signer("Signing Documents/certificate.pfx", "123", HashAlgorithmType.SHA256, tsaClient, Nothing, Nothing, PdfSignatureProfile.PAdES_BES) |
29 | | - |
30 | | - 'Apply a signature to a new form field created before |
31 | | - Dim cooperSignature = New PdfSignatureBuilder(pkcs7Signature, signatureFieldInfo) |
32 | | - |
33 | | - 'Specify an image and signer information |
34 | | - cooperSignature.SetImageData(System.IO.File.ReadAllBytes("Signing Documents/JaneCooper.jpg")) |
35 | | - cooperSignature.Location = "USA" |
36 | | - cooperSignature.Name = "Jane Cooper" |
37 | | - cooperSignature.Reason = "Acknowledgement" |
38 | | - |
39 | | - 'Apply a signature to an existing form field |
40 | | - Dim santuzzaSignature = New PdfSignatureBuilder(pkcs7Signature, "Sign") |
41 | | - |
42 | | - 'Specify an image and signer information |
43 | | - santuzzaSignature.Location = "Australia" |
44 | | - santuzzaSignature.Name = "Santuzza Valentina" |
45 | | - santuzzaSignature.Reason = "I Agree" |
46 | | - |
47 | | - ' Specify signature appearance parameters: |
48 | | - Dim signatureAppearance As New PdfSignatureAppearance() |
49 | | - signatureAppearance.SetImageData("Signing Documents/SantuzzaValentina.png") |
50 | | - signatureAppearance.SignatureDetailsFont.Size = 12 |
51 | | - signatureAppearance.SignatureDetailsFont.Italic = True |
52 | | - signatureAppearance.ShowDate = True |
53 | | - signatureAppearance.ShowReason = True |
54 | | - santuzzaSignature.SetSignatureAppearance(signatureAppearance) |
55 | | - |
56 | | - 'Create a new signature form field: |
57 | | - Dim signatureFieldInfo1 = New PdfSignatureFieldInfo(1) |
58 | | - signatureFieldInfo1.Name = "SignatureField1" |
59 | | - signatureFieldInfo1.SignatureBounds = New PdfRectangle(200, 200, 250, 250) |
60 | | - |
61 | | - 'Create a document level time stamp: |
62 | | - Dim pdfTimeStamp As New PdfTimeStamp(tsaClient) |
63 | | - |
64 | | - 'Apply this time stamp to the form field: |
65 | | - Dim timeStampSignature = New PdfSignatureBuilder(pdfTimeStamp, signatureFieldInfo1) |
66 | | - |
67 | | - 'Add signatures to an array |
68 | | - Dim signatures() As PdfSignatureBuilder = { cooperSignature, santuzzaSignature, timeStampSignature } |
69 | | - |
70 | | - 'Sign and save the document |
71 | | - signer.SaveDocument("SignedDocument.pdf", signatures) |
72 | | - End Using |
73 | | - End Sub |
74 | | - End Class |
| 16 | + Public Shared Sub ApplySignatures() |
| 17 | + 'Load a document to sign |
| 18 | + Using signer = New PdfDocumentSigner("Document.pdf") |
| 19 | + 'Specify the name and location of the signature field |
| 20 | + Dim signatureFieldInfo = New PdfSignatureFieldInfo(1) |
| 21 | + signatureFieldInfo.Name = "SignatureField" |
| 22 | + signatureFieldInfo.SignatureBounds = New PdfRectangle(20, 20, 150, 150) |
| 23 | + signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90 |
| 24 | + 'Create a timestamp |
| 25 | + Dim tsaClient As ITsaClient = New TsaClient(New Uri("https://freetsa.org/tsr"), HashAlgorithmType.SHA256) |
| 26 | + 'Create a PAdES PKCS#7 signature |
| 27 | + Dim pkcs7Signature As Pkcs7Signer = New Pkcs7Signer("Signing Documents/certificate.pfx", "123", HashAlgorithmType.SHA256, tsaClient, Nothing, Nothing, PdfSignatureProfile.PAdES_BES) |
| 28 | + 'Apply a signature to a new form field created before |
| 29 | + Dim cooperSignature = New PdfSignatureBuilder(pkcs7Signature, signatureFieldInfo) |
| 30 | + 'Specify an image and signer information |
| 31 | + cooperSignature.SetImageData(IO.File.ReadAllBytes("Signing Documents/JaneCooper.jpg")) |
| 32 | + cooperSignature.Location = "USA" |
| 33 | + cooperSignature.Name = "Jane Cooper" |
| 34 | + cooperSignature.Reason = "Acknowledgement" |
| 35 | + 'Apply a signature to an existing form field |
| 36 | + Dim santuzzaSignature = New PdfSignatureBuilder(pkcs7Signature, "Sign") |
| 37 | + 'Specify an image and signer information |
| 38 | + santuzzaSignature.Location = "Australia" |
| 39 | + santuzzaSignature.Name = "Santuzza Valentina" |
| 40 | + santuzzaSignature.Reason = "I Agree" |
| 41 | + ' Specify signature appearance parameters: |
| 42 | + Dim signatureAppearance As PdfSignatureAppearance = New PdfSignatureAppearance() |
| 43 | + signatureAppearance.SetImageData("Signing Documents/SantuzzaValentina.png") |
| 44 | + signatureAppearance.SignatureDetailsFont.Size = 12 |
| 45 | + signatureAppearance.SignatureDetailsFont.Italic = True |
| 46 | + signatureAppearance.ShowDate = True |
| 47 | + signatureAppearance.ShowReason = True |
| 48 | + santuzzaSignature.SetSignatureAppearance(signatureAppearance) |
| 49 | + 'Create a new signature form field: |
| 50 | + Dim signatureFieldInfo1 = New PdfSignatureFieldInfo(1) |
| 51 | + signatureFieldInfo1.Name = "SignatureField1" |
| 52 | + signatureFieldInfo1.SignatureBounds = New PdfRectangle(200, 200, 250, 250) |
| 53 | + 'Create a document level time stamp: |
| 54 | + Dim pdfTimeStamp As PdfTimeStamp = New PdfTimeStamp(tsaClient) |
| 55 | + 'Apply this time stamp to the form field: |
| 56 | + Dim timeStampSignature = New PdfSignatureBuilder(pdfTimeStamp, signatureFieldInfo1) |
| 57 | + 'Add signatures to an array |
| 58 | + Dim signatures As PdfSignatureBuilder() = {cooperSignature, santuzzaSignature, timeStampSignature} |
| 59 | + 'Sign and save the document |
| 60 | + signer.SaveDocument("SignedDocument.pdf", signatures) |
| 61 | + End Using |
| 62 | + End Sub |
| 63 | + End Class |
75 | 64 | End Namespace |
76 | | - |
0 commit comments