Click or drag to resize

Digital Signature Element

Digital signatures can be added to a PDF document using the DigitalSignatureElement. Adding a digital signature requires a PKCS#12 certificate provided as a .pfx or a .p12 file.

Sample Code

Below there is a sample showing how to add a digital signature to a PDF document:

// add a page to the PDF document
PdfPage firstPage = document.AddPage();

string logoImagePath = System.IO.Path.Combine(Server.MapPath("~"), @"img\logo.jpg");
string certificateFilePath = System.IO.Path.Combine(Server.MapPath("~"), "oss.pfx");

// create the area where the digital signature will be displayed in the PDF document
// in this sample the area is a logo image but it could be anything else
ImageElement logoElement = new ImageElement(0, 0, logoImagePath);
AddElementResult addResult = firstPage.AddElement(logoElement);

//get the #PKCS 12 certificate from file
DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "osspswd");
DigitalCertificate certificate = certificates[0];

// create the digital signature over the logo image element
DigitalSignatureElement signature = new DigitalSignatureElement(addResult.EndPageBounds, certificate);
signature.Reason = "Protect the document from unwanted changes";
signature.ContactInfo = "The contact email is office@outsidesoftware.com";
signature.Location = "Development server";
firstPage.AddElement(signature);