Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adobe.PDF.Library.LM.NET" Version="18.*" />
</ItemGroup>

</Project>
84 changes: 84 additions & 0 deletions Security/AddPAdESPolicySignature/AddPAdESPolicySignature.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Imports Datalogics.PDFL

'
'
' This sample program demonstrates the use of AddDigitalSignature for PAdES
' (PDF Advanced Electronic Signatures) with an explicit signature policy.
' PAdES policy signatures (EPES) conform to the ETSI EN 319 142 standard,
' use the ETSI.CAdES.detached SubFilter, and embed one or more signature
' policy identifiers along with optional policy qualifiers.
'
' Copyright (c) 2026, Datalogics, Inc. All rights reserved.
'
'
Namespace AddPAdESPolicySignature
Module AddPAdESPolicySignature
Sub Main(args As String())
Console.WriteLine("AddPAdESPolicySignature 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 = "PAdESPolicySignature-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
' PAdES signatures use SHA-384 digest with EC credentials
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).
' NOTE: Signature type must be set prior to adding policies.
sigDoc.DocSignType = SignatureType.PADES

' Define a signature policy (SigPolicyId) using an OID.
sigDoc.AddSigPolicy("2.16.724.1.3.1.1.2.1.9")

' Add a policy qualifier (SPuri) pointing to the policy specification document.
sigDoc.AddSigPolicyQualifierURI(
"https://sede.administracion.gob.es/politica_de_firma_anexo_1.pdf")

' 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
14 changes: 14 additions & 0 deletions Security/AddPAdESPolicySignature/AddPAdESPolicySignature.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adobe.PDF.Library.LM.NET" Version="18.*" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Security/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## ***AddBasicPAdESElectronicSignature***
Demonstrates adding a PAdES B-T baseline electronic signature to a PDF document.

## ***AddPAdESPolicySignature***
Demonstrates adding a PAdES B-T policy-based signature to a PDF document.

## ***AddDigitalSignatureCMS***
Demonstrates adding a digital signature with a logo to a PDF document.

Expand Down
2 changes: 2 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
'OpticalCharacterRecognition/OCRDocument/',
'Other/MemoryFileSystem/',
'Other/StreamIO/',
'Security/AddBasicPAdESElectronicSignature/',
'Security/AddPAdESPolicySignature/',
'Security/AddDigitalSignatureCMS/',
'Security/AddDigitalSignatureRFC3161/',
'Security/AddRegexRedaction/',
Expand Down