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