Digital Signing

A PDF document can have a digital ID applied to it or a digital signature can be added so it is part of the Document but not actually viewable from any of the pages. The following two topics discuss this distinction.

Visible Digital Signatures

A PDF document can have a digital ID applied to it in order to be digitally signed. That digital ID can either be added to visually appear on the page of the PDF (through a Signature Field) or they can be added so that the digital signature is just a part of the document's properties (and not a visible part of any pages).

To add signatures as visible fields in the document you must first create and add a Signature Field to a Page (this defines where the signature will be visible on that page), then create a Certificate object (based on the personal information exchange file or PFX and the password) then finally you must call the Document object's Sign method passing in the name of the Signature Field and the Certificate object.

The following example demonstrates adding a visible digital signature to a PDF document:

Document document = new Document();
Page page = new Page();

//Create add Signature Form Field
Signature signature = new Signature("SigField", 10, 10, 250, 100);
page.Elements.Add(signature);
document.Pages.Add(page);
Certificate certificate = new Certificate(@"C:\PersonalFiles\JohnDoe.pfx", "password");

// Field name should be one of the signature field name 
document.Sign("SigField", certificate);
document.Draw(pdfFilePath);        
Dim MyDocument As New Document()
Dim MyPage = New Page()

' Create add Signature Form Field
Dim MySignature As New Signature("SigField", 10, 10, 250, 100)
MyPage.Elements.Add(MySignature)
MyDocument.Pages.Add(MyPage)
Dim MyCertificate As New Certificate("C:\PersonalFiles\JohnDoe.pfx", "password")

' Field name should be one of the signature field name 
MyDocument.Sign("SigField", MyCertificate)
MyDocument.Draw(pdfFilePath)    

Invisible Digital Signatures

Alternatively, digital signatures can be added so that they are part of the Document but not actually viewable from any of the pages. To accomplish this just omit the creating of the Signature Field from the above example. In the Document's Sign method make sure to specify a string that does not match the name of any form fields on the document. If the field name passed into the Document's Sign method does match a field but it is a non-signature field then the document will be left unsigned. Also worth noting here is that the Document's Sign method can only be called once (allowing only one signature to be associated with each document).

The following example demonstrates adding an invisible digital signature to a PDF document:

Document document = new Document();
Page page = new Page();

document.Pages.Add(page);
Certificate certificate = new Certificate(@"C:\PersonalFiles\JohnDoe.pfx", "password");

// Field name should not match any field names in the document 
document.Sign("NonExistingField", certificate);
document.Draw(pdfFilePath);        
Dim MyDocument As New Document()
Dim MyPage = New Page()

MyDocument.Pages.Add(MyPage)
Dim MyCertificate As New Certificate("C:\PersonalFiles\JohnDoe.pfx", "password")

' Field name should not match any field names in the document 
MyDocument.Sign("NonExistingField", MyCertificate)
MyDocument.Draw(pdfFilePath)

In this topic