Digitally Sign a PDF Document

Important Disambiguation: Signing a PDF

Developers commonly ask how they can programmatically add a signature to a PDF document using IronPDF. Commonly, signing means different things to different developers:

  1. To digitally sign a PDF document with a Certificate to ensure it can not been tampered with.
  2. To add a graphical handwritten signature image to an existing PDF from an image file.
  3. To stamp a Certificate's Image onto a PDF.
  4. To add a Signature Form Field to a PDF which some viewers can prompt for Signing.

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf

Download DLL

Download DLL

Manually install into your project

Sign a PDF with a Digital Certificate

IronPDF supports many ways to sign a PDF with a digital signature certificate. In this How-To guide, you will be guided through every approach.

Supported Digital Signature Certificate Files

We officially comply to the X509Certificate2 standard. Which may support .pfx and .p12 signatures. If your signature is unable to be applied directly in IronPDF's signing methods, you will need to create a X509Certificate2 certificate with instructions that can be found here. IronPDF's Signing methods will accept any X509Certificate2 variable.

Sign a PdfDocument

There are three main methods used to digitally sign your PDF:

Signature Method
SignSign a PDF with a PdfSignature object
SignWithFileSign PDF with a digital signature certificate on disk
SignWithStoreSigns the PDF with digital signature extracted from your computer's signature storage. Based on a thumbprint ID

Understanding Incremental Saving for Signatures

While some viewers like Chrome browser only show one version, PDF files have the capability to store previous versions of the document similar to a Git commit history. You will see this in more advanced PDF viewers such as Adobe Acrobat.

When dealing with PDF signatures, it is important to know about this because the action of signing a PDF applies to the current iteration of the PDF. Your PDF may have signatures for older iterations, or may have a few unsigned versions. We can visualize an example like follows:

PDF Document IterationCertificate ACertificate BCertificate CCertificate D
0 (first save)
(form field edits only)

(form field edits only)
4 (only form fields edited)
(no further edits allowed)

(no further edits allowed)

(no further edits allowed)

Above, we have a documents that has been through 6 different iterations. This document may be being passed around departments of a company with approval until being finalized at iteration 3. In this iteration, both Person A and Person B signed the document with the permission "Form Field Edits Only" set. This means that filling in form fields in the PDF document is allowed, but any other change to the document will invalidate their signatures.

In the example above we can assume Person C is the one who has filled out the form and sent it back to Person A, C, and D who all signed the document a final time with the "No Edits Allowed" permission. Because no illegal actions were taken in this document invalidating signatures, when we run IronPDF's signature method we will get true.

Save and Sign a PDF Revision Iteration

In the following example we open a PDF file, make various edits, then before we save we will sign it. For signature permissions, we will only allow form-filling as future edits, otherwise the signature will be invalidated from any other edit.

We will then call SaveAsRevision to save the revision to the history and then save our new document to disk.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("annual_census.pdf");
// ... various edits ...
pdf.SignWithFile("/assets/IronSignature.p12", "password", null, PdfDocument.SignaturePermissions.FormFillingAllowed);

PdfDocument pdfWithRevision = pdf.SaveAsRevision();

Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("annual_census.pdf")
' ... various edits ...
pdf.SignWithFile("/assets/IronSignature.p12", "password", Nothing, PdfDocument.SignaturePermissions.FormFillingAllowed)

Dim pdfWithRevision As PdfDocument = pdf.SaveAsRevision()

VB   C#

Signature Permissions

If you choose, you may explicitly specify conditions that your Certificate will remain valid. If you want your Signature invalidated upon and change, or allowing just form field changes, etc. Pleaase use the following table to see the options:

NoChangesAllowedNo changes are allowed
FormFillingAllowedChanging form field values is allowed
FormFillingAndAnnotationsAllowedChanging form field values and modifying annotations are allowed

This paramter is optional and not setting it will apply a signature that certifies a specific revision and cannot be invalidated.

Remove Signatures

IronPDF has a method RemoveSignatures that will remove every signature of every revision for a PDF document. Usage is as follows:

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("invoice.pdf")
VB   C#

Roll back to an Old Revision

To roll back to a previous revision of a PDF, you can use the GetRevision method. This will forget any changes made since this revision including newer signatures. To do this use:

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("report.pdf");

int versions = pdf.RevisionCount; // total revisions

PdfDocument rolledBackPdf = pdf.GetRevision(2);
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("report.pdf")

Private versions As Integer = pdf.RevisionCount ' total revisions

Private rolledBackPdf As PdfDocument = pdf.GetRevision(2)
VB   C#

Verify All Signatures in a PDF

Calling the verify signatures method on a PDF document will look at all Signatures from all document iterations and verify that all of them are still valid. This will return a bool of true if they are all valid.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("annual_census.pdf");
bool isValid = pdf.VerifyPdfSignatures();
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("annual_census.pdf")
Private isValid As Boolean = pdf.VerifyPdfSignatures()
VB   C#

Stamp a Signature onto a PDF

First off, I will start with a PDF I want to sign. I will use this example invoice:

We will apply a handwritten signature which is in the form of a .png image to our PDF. This may be a handwritten signature or the image that was used in the creation of a certificate file. This is the sample signature we will use:


With this we will use the following code to stamp the handwritten signature to the PDF as a watermark:

using IronPdf;
using IronPdf.Editing;

var pdf = PdfDocument.FromFile("invoice.pdf");

pdf.ApplyWatermark("<img src='signature.png'/>", 90, VerticalAlignment.Bottom, HorizontalAlignment.Right);

Imports IronPdf
Imports IronPdf.Editing

Private pdf = PdfDocument.FromFile("invoice.pdf")

pdf.ApplyWatermark("<img src='signature.png'/>", 90, VerticalAlignment.Bottom, HorizontalAlignment.Right)

VB   C#

Output Result

After this code is run, we have this output file which has our signature on the bottom right:

Add a Signature Form Field to a PDF

This is not currently supported yet. You can read more about IronPDF and the forms it supports in the Programmatically Fill PDF Forms in C# article.