-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAddBasicPAdESElectronicSignature.vb
More file actions
76 lines (64 loc) · 3.44 KB
/
AddBasicPAdESElectronicSignature.vb
File metadata and controls
76 lines (64 loc) · 3.44 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
64
65
66
67
68
69
70
71
72
73
74
75
76
Imports Datalogics.PDFL
'
'
' This sample program demonstrates the use of AddDigitalSignature for PAdES
' (PDF Advanced Electronic Signatures) baseline signature type without a
' signature policy. PAdES signatures conform to the ETSI standard and use
' the ETSI.CAdES.detached SubFilter.
'
' Copyright (c) 2026, Datalogics, Inc. All rights reserved.
'
'
Namespace AddBasicPAdESElectronicSignature
Module AddBasicPAdESElectronicSignature
Sub Main(args As String())
Console.WriteLine("AddBasicPAdESElectronicSignature Sample:")
Using New Library()
Console.WriteLine("Initialized the library.")
Dim sInput As String = Library.ResourceDirectory & "Sample_Input/SixPages.pdf"
Dim sLogo As String = Library.ResourceDirectory & "Sample_Input/ducky_alpha.tif"
Dim sOutput As String = "PAdESBaselineSignature-out.pdf"
Dim sPEMCert As String = Library.ResourceDirectory & "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem"
Dim sPEMKey As String = Library.ResourceDirectory & "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem"
If (args.Length > 0) Then
sInput = args(0)
End If
If (args.Length > 1) Then
sOutput = args(1)
End If
If (args.Length > 2) Then
sLogo = args(2)
End If
Console.WriteLine("Input file: " & sInput)
Console.WriteLine("Writing to output: " & sOutput)
Using doc As New Document(sInput)
Using sigDoc As New SignDoc()
' Setup Sign params
sigDoc.FieldID = SignatureFieldID.CreateFieldWithQualifiedName
sigDoc.FieldName = "Signature_es_:signatureblock"
' Set credential related attributes
sigDoc.DigestCategory = DigestCategory.Sha384
sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX
sigDoc.SetNonPfxSignerCert(sPEMCert, 0, CredentialStorageFmt.OnDisk)
sigDoc.SetNonPfxPrivateKey(sPEMKey, 0, CredentialStorageFmt.OnDisk)
' Set the signature type to PAdES (PDF Advanced Electronic Signatures).
' This produces an ETSI.CAdES.detached signature conforming to the
' PAdES baseline profile without a signature policy.
sigDoc.DocSignType = SignatureType.PADES
' Setup the signer information
' (Logo image is optional)
sigDoc.SetSignerInfo(sLogo, 0.5F, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.", DisplayTraits.KDisplayAll)
' Set the size and location of the signature box (optional)
' If not set, invisible signature will be placed on first page
sigDoc.SignatureBoxPageNumber = 0
sigDoc.SignatureBoxRectangle = New Rect(100, 300, 400, 400)
' Setup Save params
sigDoc.OutputPath = sOutput
' Finally, sign and save the document
sigDoc.AddDigitalSignature(doc)
End Using
End Using
End Using
End Sub
End Module
End Namespace