Skip to content
Open
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,84 @@
using Datalogics.PDFL;
using System;

/*
*
* 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
{
class AddBasicPAdESElectronicSignature
{
static void Main(string[] args)
{
Console.WriteLine("AddBasicPAdESElectronicSignature Sample:");

using (new Library())
{
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
String sOutput = "PAdESBaselineSignature-out.pdf";

String sPEMCert = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem";
String sPEMKey = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem";

if (args.Length > 0)
sInput = args[0];

if (args.Length > 1)
sOutput = args[1];

if (args.Length > 2)
sLogo = args[2];

Console.WriteLine("Input file: " + sInput);
Console.WriteLine("Writing to output: " + sOutput);

using (Document doc = new Document(sInput))
{
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.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);
}
}
}
}
}
}
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>
92 changes: 92 additions & 0 deletions Security/AddPAdESPolicySignature/AddPAdESPolicySignature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Datalogics.PDFL;
using System;

/*
*
* 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
{
class AddPAdESPolicySignature
{
static void Main(string[] args)
{
Console.WriteLine("AddPAdESPolicySignature Sample:");

using (new Library())
{
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
String sOutput = "PAdESPolicySignature-out.pdf";

String sPEMCert = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem";
String sPEMKey = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem";

if (args.Length > 0)
sInput = args[0];

if (args.Length > 1)
sOutput = args[1];

if (args.Length > 2)
sLogo = args[2];

Console.WriteLine("Input file: " + sInput);
Console.WriteLine("Writing to output: " + sOutput);

using (Document doc = new Document(sInput))
{
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.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);
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions Security/AddPAdESPolicySignature/AddPAdESPolicySignature.csproj
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 @@ -74,6 +74,8 @@
'OpticalCharacterRecognition/OCRDocument/',
'Other/MemoryFileSystem/',
'Other/StreamIO/',
'Security/AddBasicPAdESElectronicSignature/',
'Security/AddPAdESPolicySignature/',
'Security/AddDigitalSignatureCMS/',
'Security/AddDigitalSignatureRFC3161/',
'Security/AddRegexRedaction/',
Expand Down