Skip to content

Commit 142cd05

Browse files
Merge pull request #68 from datalogics-saharay/APDFL-6596-add-PAdES-EPES-digsig-sample
APDFL-6596: Add .NET Framework sample for PAdES policy-based signatures
2 parents 5362ad3 + aebfca2 commit 142cd05

7 files changed

Lines changed: 196 additions & 0 deletions

File tree

.github/workflows/test-net-framework-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
'Printing/PrintPDF/',
9595
'Printing/PrintPDFGUI/',
9696
'Security/AddBasicPAdESElectronicSignature/',
97+
'Security/AddPAdESPolicySignature/',
9798
'Security/AddDigitalSignatureCMS/',
9899
'Security/AddDigitalSignatureRFC3161/',
99100
'Security/AddRegexRedaction/',

Samples.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureCMS", "S
186186
EndProject
187187
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureRFC3161", "Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.csproj", "{74FA984E-AB89-475A-9077-9D612DE12AEC}"
188188
EndProject
189+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddPAdESPolicySignature", "Security\AddPAdESPolicySignature\AddPAdESPolicySignature.csproj", "{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}"
190+
EndProject
189191
Global
190192
GlobalSection(SolutionConfigurationPlatforms) = preSolution
191193
Debug|x64 = Debug|x64
@@ -560,6 +562,10 @@ Global
560562
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.Build.0 = Debug|x64
561563
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.ActiveCfg = Release|x64
562564
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.Build.0 = Release|x64
565+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Debug|x64.ActiveCfg = Debug|x64
566+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Debug|x64.Build.0 = Debug|x64
567+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Release|x64.ActiveCfg = Release|x64
568+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Release|x64.Build.0 = Release|x64
563569
EndGlobalSection
564570
GlobalSection(SolutionProperties) = preSolution
565571
HideSolutionNode = FALSE
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Datalogics.PDFL;
5+
6+
/*
7+
*
8+
* This sample program demonstrates the use of AddDigitalSignature for PAdES
9+
* (PDF Advanced Electronic Signatures) with an explicit signature policy.
10+
* PAdES policy signatures (EPES) conform to the ETSI EN 319 142 standard,
11+
* use the ETSI.CAdES.detached SubFilter, and embed one or more signature
12+
* policy identifiers along with optional policy qualifiers.
13+
*
14+
* Copyright (c) 2026, Datalogics, Inc. All rights reserved.
15+
*
16+
*/
17+
namespace AddPAdESPolicySignature
18+
{
19+
class AddPAdESPolicySignature
20+
{
21+
static void Main(string[] args)
22+
{
23+
Console.WriteLine("AddPAdESPolicySignature Sample:");
24+
25+
using (new Library())
26+
{
27+
Console.WriteLine("Initialized the library.");
28+
29+
String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
30+
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
31+
String sOutput = "PAdESPolicySignature-out.pdf";
32+
33+
String sPEMCert = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem";
34+
String sPEMKey = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem";
35+
36+
if (args.Length > 0)
37+
sInput = args[0];
38+
39+
if (args.Length > 1)
40+
sOutput = args[1];
41+
42+
if (args.Length > 2)
43+
sLogo = args[2];
44+
45+
Console.WriteLine("Input file: " + sInput);
46+
Console.WriteLine("Writing to output: " + sOutput);
47+
48+
using (Document doc = new Document(sInput))
49+
{
50+
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.SignDoc())
51+
{
52+
// Setup Sign params
53+
sigDoc.FieldID = SignatureFieldID.CreateFieldWithQualifiedName;
54+
sigDoc.FieldName = "Signature_es_:signatureblock";
55+
56+
// Set credential related attributes
57+
// PAdES signatures use SHA-384 digest with EC credentials
58+
sigDoc.DigestCategory = DigestCategory.Sha384;
59+
sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX;
60+
sigDoc.SetNonPfxSignerCert(sPEMCert, 0, CredentialStorageFmt.OnDisk);
61+
sigDoc.SetNonPfxPrivateKey(sPEMKey, 0, CredentialStorageFmt.OnDisk);
62+
63+
// Set the signature type to PAdES (PDF Advanced Electronic Signatures).
64+
// NOTE: Signature type must be set prior to adding policies.
65+
sigDoc.DocSignType = SignatureType.PADES;
66+
67+
// Define a signature policy (SigPolicyId) using an OID.
68+
sigDoc.AddSigPolicy("2.16.724.1.3.1.1.2.1.9");
69+
70+
// Add a policy qualifier (SPuri) pointing to the policy specification document.
71+
sigDoc.AddSigPolicyQualifierURI(
72+
"https://sede.administracion.gob.es/politica_de_firma_anexo_1.pdf");
73+
74+
// Setup the signer information
75+
// (Logo image is optional)
76+
sigDoc.SetSignerInfo(sLogo, 0.5F, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.",
77+
DisplayTraits.KDisplayAll);
78+
79+
// Set the size and location of the signature box (optional)
80+
// If not set, invisible signature will be placed on first page
81+
sigDoc.SignatureBoxPageNumber = 0;
82+
sigDoc.SignatureBoxRectangle = new Rect(100, 300, 400, 400);
83+
84+
// Setup Save params
85+
sigDoc.OutputPath = sOutput;
86+
87+
// Finally, sign and save the document
88+
sigDoc.AddDigitalSignature(doc);
89+
}
90+
}
91+
}
92+
}
93+
}
94+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
7+
<ProjectGuid>{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>AddPAdESPolicySignature</RootNamespace>
10+
<AssemblyName>AddPAdESPolicySignature</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
19+
<PlatformTarget>x64</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="AddPAdESPolicySignature.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="App.config" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<PackageReference Include="Adobe.PDF.Library.LM.NETFramework">
55+
<Version>18.*</Version>
56+
</PackageReference>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Folder Include="Properties\" />
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.14.36414.22 d17.14
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddPAdESPolicySignature", "AddPAdESPolicySignature.csproj", "{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x64 = Debug|x64
10+
Release|x64 = Release|x64
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Debug|x64.ActiveCfg = Debug|x64
14+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Debug|x64.Build.0 = Debug|x64
15+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Release|x64.ActiveCfg = Release|x64
16+
{D4E8A2B1-6F3C-4D5E-9A7B-1C2D3E4F5A6B}.Release|x64.Build.0 = Release|x64
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {B7F3A1C2-8D4E-5F6A-9B0C-2D3E4F5A6B7C}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Security/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## ***AddBasicPAdESElectronicSignature***
22
Demonstrates adding a PAdES B-T baseline electronic signature to a PDF document.
33

4+
## ***AddPAdESPolicySignature***
5+
Demonstrates adding a PAdES B-T policy-based signature to a PDF document.
6+
47
## ***AddDigitalSignatureCMS***
58
Demonstrates adding a digital signature with a logo to a PDF document.
69

0 commit comments

Comments
 (0)