Skip to content

Commit 5362ad3

Browse files
Merge pull request #67 from datalogics-saharay/APDFL-6595-add-PAdES-without-policy-sample
Add PAdES baseline electronic signature sample for .NET Framework
2 parents 8fb2273 + 582b96c commit 5362ad3

7 files changed

Lines changed: 188 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
@@ -93,6 +93,7 @@ jobs:
9393
'Other/StreamIO/',
9494
'Printing/PrintPDF/',
9595
'Printing/PrintPDFGUI/',
96+
'Security/AddBasicPAdESElectronicSignature/',
9697
'Security/AddDigitalSignatureCMS/',
9798
'Security/AddDigitalSignatureRFC3161/',
9899
'Security/AddRegexRedaction/',

Samples.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexTextSearch", "Text\Reg
180180
EndProject
181181
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextExtract", "Text\TextExtract\TextExtract.csproj", "{11C4A647-3DDA-41A5-855C-E14EDF1BFFDE}"
182182
EndProject
183+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddBasicPAdESElectronicSignature", "Security\AddBasicPAdESElectronicSignature\AddBasicPAdESElectronicSignature.csproj", "{C7DF1472-B78F-402E-8841-52D2CB2B4725}"
184+
EndProject
183185
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureCMS", "Security\AddDigitalSignatureCMS\AddDigitalSignatureCMS.csproj", "{AB753937-DF3D-4B06-B475-D3B597D32BC5}"
184186
EndProject
185187
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureRFC3161", "Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.csproj", "{74FA984E-AB89-475A-9077-9D612DE12AEC}"
@@ -554,6 +556,10 @@ Global
554556
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.Build.0 = Debug|x64
555557
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.ActiveCfg = Release|x64
556558
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.Build.0 = Release|x64
559+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.ActiveCfg = Debug|x64
560+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.Build.0 = Debug|x64
561+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.ActiveCfg = Release|x64
562+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.Build.0 = Release|x64
557563
EndGlobalSection
558564
GlobalSection(SolutionProperties) = preSolution
559565
HideSolutionNode = FALSE
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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) baseline signature type without a
10+
* signature policy. PAdES signatures conform to the ETSI standard and use
11+
* the ETSI.CAdES.detached SubFilter.
12+
*
13+
* Copyright (c) 2026, Datalogics, Inc. All rights reserved.
14+
*
15+
*/
16+
namespace AddBasicPAdESElectronicSignature
17+
{
18+
class AddBasicPAdESElectronicSignature
19+
{
20+
static void Main(string[] args)
21+
{
22+
Console.WriteLine("AddBasicPAdESElectronicSignature Sample:");
23+
24+
using (new Library())
25+
{
26+
Console.WriteLine("Initialized the library.");
27+
28+
String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
29+
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
30+
String sOutput = "PAdESBaselineSignature-out.pdf";
31+
32+
String sPEMCert = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem";
33+
String sPEMKey = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem";
34+
35+
if (args.Length > 0)
36+
sInput = args[0];
37+
38+
if (args.Length > 1)
39+
sOutput = args[1];
40+
41+
if (args.Length > 2)
42+
sLogo = args[2];
43+
44+
Console.WriteLine("Input file: " + sInput);
45+
Console.WriteLine("Writing to output: " + sOutput);
46+
47+
using (Document doc = new Document(sInput))
48+
{
49+
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.SignDoc())
50+
{
51+
// Setup Sign params
52+
sigDoc.FieldID = SignatureFieldID.CreateFieldWithQualifiedName;
53+
sigDoc.FieldName = "Signature_es_:signatureblock";
54+
55+
// Set credential related attributes
56+
sigDoc.DigestCategory = DigestCategory.Sha384;
57+
sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX;
58+
sigDoc.SetNonPfxSignerCert(sPEMCert, 0, CredentialStorageFmt.OnDisk);
59+
sigDoc.SetNonPfxPrivateKey(sPEMKey, 0, CredentialStorageFmt.OnDisk);
60+
61+
// Set the signature type to PAdES (PDF Advanced Electronic Signatures).
62+
// This produces an ETSI.CAdES.detached signature conforming to the
63+
// PAdES baseline profile without a signature policy.
64+
sigDoc.DocSignType = SignatureType.PADES;
65+
66+
// Setup the signer information
67+
// (Logo image is optional)
68+
sigDoc.SetSignerInfo(sLogo, 0.5F, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.",
69+
DisplayTraits.KDisplayAll);
70+
71+
// Set the size and location of the signature box (optional)
72+
// If not set, invisible signature will be placed on first page
73+
sigDoc.SignatureBoxPageNumber = 0;
74+
sigDoc.SignatureBoxRectangle = new Rect(100, 300, 400, 400);
75+
76+
// Setup Save params
77+
sigDoc.OutputPath = sOutput;
78+
79+
// Finally, sign and save the document
80+
sigDoc.AddDigitalSignature(doc);
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}
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>{C7DF1472-B78F-402E-8841-52D2CB2B4725}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>AddBasicPAdESElectronicSignature</RootNamespace>
10+
<AssemblyName>AddBasicPAdESElectronicSignature</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="AddBasicPAdESElectronicSignature.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}") = "AddBasicPAdESElectronicSignature", "AddBasicPAdESElectronicSignature.csproj", "{C7DF1472-B78F-402E-8841-52D2CB2B4725}"
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+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.ActiveCfg = Debug|x64
14+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.Build.0 = Debug|x64
15+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.ActiveCfg = Release|x64
16+
{C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.Build.0 = Release|x64
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {1320D004-1376-4D4F-BFD2-A33DC360756F}
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,3 +1,6 @@
1+
## ***AddBasicPAdESElectronicSignature***
2+
Demonstrates adding a PAdES B-T baseline electronic signature to a PDF document.
3+
14
## ***AddDigitalSignatureCMS***
25
Demonstrates adding a digital signature with a logo to a PDF document.
36

0 commit comments

Comments
 (0)