Skip to content

Commit 99bbd17

Browse files
Add Digital Signature sample
Fix csproj Add sample to github actions
1 parent 35012c4 commit 99bbd17

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

.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/AddDigitalSignature/',
9697
'Security/AddRegexRedaction/',
9798
'Security/Redactions/',
9899
'Text/AddGlyphs/',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.
9+
*
10+
* Copyright (c) 2025, Datalogics, Inc. All rights reserved.
11+
*
12+
*/
13+
namespace AddDigitalSignature
14+
{
15+
class AddDigitalSignature
16+
{
17+
static void Main(string[] args)
18+
{
19+
Console.WriteLine("AddDigitalSignature Sample:");
20+
21+
using (new Library())
22+
{
23+
Console.WriteLine("Initialized the library.");
24+
25+
String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
26+
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
27+
String sOutput = "DigSig-out.pdf";
28+
29+
if (args.Length > 0)
30+
sInput = args[0];
31+
32+
if (args.Length > 1)
33+
sOutput = args[1];
34+
35+
if (args.Length > 2)
36+
sLogo = args[2];
37+
38+
Console.WriteLine("Input file: " + sInput);
39+
Console.WriteLine("Writing to output: " + sOutput);
40+
41+
using (Document doc = new Document(sInput))
42+
{
43+
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.SignDoc())
44+
{
45+
// Setup Sign params
46+
sigDoc.FieldID = SignatureFieldID.CreateFieldWithQualifiedName;
47+
sigDoc.FieldName = "Signature_es_:signatureblock";
48+
49+
// Set credential related attributes
50+
sigDoc.DigestCategory = DigestCategory.Sha256;
51+
sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX;
52+
sigDoc.SetNonPfxSignerCert("Credentials/DER/RSA_certificate.der", 0, CredentialStorageFmt.OnDisk);
53+
sigDoc.SetNonPfxPrivateKey("Credentials/DER/RSA_privKey.der", 0, CredentialStorageFmt.OnDisk);
54+
55+
// Setup the signer information
56+
// (Logo image is optional)
57+
sigDoc.SetSignerInfo(sOutput, 0.5, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.",
58+
DisplayTraits.KDisplayAll);
59+
60+
// Set the size and location of the signature box (optional)
61+
// If not set, invisible signature will be placed on first page
62+
sigDoc.SignatureBoxPageNumber = 0;
63+
sigDoc.SignatureBoxRectangle = new Rect(100, 300, 400, 400);
64+
65+
// Setup Save params
66+
sigDoc.OutputPath = sOutput;
67+
68+
// Finally, sign and save the document
69+
sigDoc.AddDigitalSignature(doc);
70+
71+
Console.WriteLine();
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
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>{3790CE63-DB43-4F16-8226-BDFEFA25BCDD}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>AddDigitalSignature</RootNamespace>
10+
<AssemblyName>AddDigitalSignature</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="AddDigitalSignature.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: 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+
## ***AddDigitalSignature***
2+
Demonstrates adding a digital signature with a logo to a PDF document.
3+
14
## ***AddRegexRedaction***
25
Uses a regular expression to find a specified phrase of text in a PDF document and then redacts that text.
36

0 commit comments

Comments
 (0)