-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAddDigitalSignatureCMS.cs
More file actions
84 lines (68 loc) · 3.26 KB
/
Copy pathAddDigitalSignatureCMS.cs
File metadata and controls
84 lines (68 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Text;
using Datalogics.PDFL;
/*
*
* This sample program demonstrates the use of AddDigitalSignature for CMS signature type.
*
* Copyright (c) 2025, Datalogics, Inc. All rights reserved.
*
*/
namespace AddDigitalSignatureCMS
{
class AddDigitalSignatureCMS
{
static void Main(string[] args)
{
Console.WriteLine("AddDigitalSignatureCMS 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 = "DigSigCMS-out.pdf";
String sDERCert = Library.ResourceDirectory + "Sample_Input/Credentials/DER/RSA_certificate.der";
String sDERKey = Library.ResourceDirectory + "Sample_Input/Credentials/DER/RSA_privKey.der";
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.Sha256;
sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX;
sigDoc.SetNonPfxSignerCert(sDERCert, 0, CredentialStorageFmt.OnDisk);
sigDoc.SetNonPfxPrivateKey(sDERKey, 0, CredentialStorageFmt.OnDisk);
// Set the signature type to be used.
// The available types are defined in the SignatureType enum. Default CMS.
sigDoc.DocSignType = SignatureType.CMS;
// 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);
Console.WriteLine();
}
}
}
}
}
}