How to Sign a PDF Document in C# and VB

Developers commonly ask how they can programmatically add a signature to a PDF document using Iron PDF and C# or VB.NET

Commonly this means different things to different developers:

  1. To add a graphical handwritten signature image to an existing Pdf from an image file
  2. To cryptographically sign a PDF document to ensure it can not been tampered with
  3. To cryptographically sign a PDF document h AND add a human handwritten signature.

1 - Stamping a Handwritten Signature onto a PDF Page

This method will stamp a signature PNG onto an existing PDF page. It could be used for a company stamp or a hand written signature. Opacity is Supported.

The HtmlStamp class supports stamping of any HTML content, which may be resized and positioned on the page using: Width, Height, Top, Bottom, Left and Right in Pixels


//PDFs can be edited or amended by stamping new HTML content into the foreground or background.

using IronPdf;

// open an existing PDF document or create a new one

PdfDocument Pdf = PdfDocument.FromFile(@"C:\Path\To\UnSigned.pdf");

var SignatureStamp = new HtmlStamp() { Html = "<img src='signature.png' />", Width = 150, Height = 50, Bottom = 300, Left=85, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };

Pdf.StampHTML(SignatureStamp,1);

Pdf.SaveAs(@"C:\Path\To\Signed.pdf");
'PDFs can be edited or amended by stamping new HTML content into the foreground or background.
Imports IronPdf
Dim Pdf As PdfDocument = PdfDocument.FromFile("C:\Path\To\UnSigned.pdf")
Dim SignatureStamp As var = New HtmlStamp
Pdf.StampHTML(SignatureStamp, 1)
Pdf.SaveAs("C:\Path\To\Signed.pdf")
VB   C#

2 - Cryptographically signing a PDF document

The following method cryptographically signs a PDF using a .pfx and .p12 digital certificate which can be created easily from with Adobe Reader.

Read: https://helpx.adobe.com/acrobat/using/digital-ids.html


using IronPdf;

// 123456 below represents the signature password

new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("UnSecure.pdf");
Imports IronPdf
' 123456 below represents the signature password
(New IronPdf.PdfSignature("CertificateFile.p12", "123456") + SignPdfFile("UnSecure.pdf"))
VB   C#

3 - Cryptographically signing a PDF document and do so with a Hand Written signature.

This more advanced example allows the .pfx / .p12 digital id signing method to be combined with a scan of a handwritten signature.


var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");

// Step 3. Optional signing options and a handwritten Signature graphic

Signature.SigningContact = "support@ironsoftware.com";

Signature.SigningLocation = "Chicago, USA";

Signature.SigningReason = "To show how to sign a PDF";

Signature.LoadSignatureImageFromFile("handwriting.png");

Signature.SignPdfFile("UnSecure.pdf");
Dim Signature As var = New IronPdf.PdfSignature("Iron.pfx", "123456")
' Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com"
Signature.SigningLocation = "Chicago, USA"
Signature.SigningReason = "To show how to sign a PDF"
Signature.LoadSignatureImageFromFile("handwriting.png")
Signature.SignPdfFile("UnSecure.pdf")
VB   C#

Cryptographic PDF signing may also be achieved during the PDF creation and rendering ( HTML to PDF ) process

// Step 1. Create a PDF

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();

PdfDocument doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");

// Step 2. Create a Signature.

// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.

// Read: https://helpx.adobe.com/acrobat/using/digital-ids.html

var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");

// Step 3. Optional signing options and a handwritten Signature graphic

Signature.SigningContact = "support@ironsoftware.com";

Signature.SigningLocation = "Chicago, USA";

Signature.SigningReason = "To show how to sign a PDF";

Signature.LoadSignatureImageFromFile("handwriting.png");

//Step 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used

doc.SignPdfWithDigitalSignature(Signature);

//Step 4. The PDF is not signed until saved to file, steam or byte array.

doc.SaveAs("signed.pdf");
Dim Renderer As IronPdf.HtmlToPdf = New IronPdf.HtmlToPdf
Dim doc As PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")
Dim Signature As var = New IronPdf.PdfSignature("Iron.pfx", "123456")
' Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com"
Signature.SigningLocation = "Chicago, USA"
Signature.SigningReason = "To show how to sign a PDF"
Signature.LoadSignatureImageFromFile("handwriting.png")
'Step 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(Signature)
'Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf")
VB   C#