DEV Community

IronSoftware
IronSoftware

Posted on

How to Digitally Sign PDF in C# (Tutorial)

Our contracts lacked authentication. Recipients couldn't verify they came from us. Legal disputes arose over document authenticity.

Digital signatures solved this. Cryptographic proof of origin and integrity. Here's the implementation.

How Do I Digitally Sign a PDF?

Use a certificate file (.pfx or .p12):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

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

pdf.SignWithFile("certificate.pfx", "password");

pdf.SaveAs("signed.pdf");
Enter fullscreen mode Exit fullscreen mode

The signature proves the PDF came from you and hasn't been modified.

Where Do I Get a Certificate?

Purchase from Certificate Authority: DigiCert, GlobalSign, Sectigo
Self-signed: For internal use only (not trusted publicly)

// Generate self-signed certificate (Windows)
// makecert -r -pe -n "CN=MyCompany" -sky signature certificate.cer

// Export to PFX with private key
Enter fullscreen mode Exit fullscreen mode

How Do I Verify a Signature?

Open in Adobe Acrobat. Signed PDFs show a blue ribbon icon. Click it to see:

  • Signer identity
  • Signature date
  • Whether document was modified

Can I Add Visible Signatures?

Yes, specify page and coordinates:

var signature = new IronPdf.Signing.PdfSignature("certificate.pfx", "password")
{
    SignatureImage = new IronPdf.Signing.SignatureImage("signature.png"),
    X = 50,
    Y = 700,
    Width = 200,
    Height = 100
};

pdf.Sign(signature, 0); // Page 0
pdf.SaveAs("signed-visible.pdf");
Enter fullscreen mode Exit fullscreen mode

Signature appears on the PDF page.

How Do I Sign with X509Certificate2?

Use certificate from store:

using System.Security.Cryptography.X509Certificates;

var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);

var cert = store.Certificates.Find(X509FindType.FindBySubjectName, "MyCompany", false)[0];

pdf.SignWithCertificate(cert);
pdf.SaveAs("signed.pdf");
Enter fullscreen mode Exit fullscreen mode

Can I Add Multiple Signatures?

Yes, for multi-party agreements:

// First signer
pdf.SignWithFile("signer1.pfx", "password1");

// Second signer (incremental update)
pdf.SignWithFile("signer2.pfx", "password2");

pdf.SaveAs("multi-signed.pdf");
Enter fullscreen mode Exit fullscreen mode

Each signature is independent.

How Do I Set Signature Permissions?

Control what's allowed after signing:

pdf.SignWithFile("certificate.pfx", "password", null, SignaturePermissions.FormFillingAllowed);
Enter fullscreen mode Exit fullscreen mode

Options: NoChangesAllowed, FormFillingAllowed, AdditionalSignaturesAllowed


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)