Syncfusion Feedback

Add Digital Signatures to PDFs in C# with the .NET PDF Library

The Syncfusion® .NET PDF Library offers powerful capabilities for creating, reading, and editing PDF documents. Users can apply digital signatures to PDF files to improve document authenticity, integrity, and security.

Watch this video to see how to digitally sign PDF files using the Syncfusion .NET PDF Library:

Watch the video

Add digital signatures to PDF documents in C#

Learn how to programmatically add digital signatures to PDF files in C# using the Syncfusion .NET PDF Library. This step-by-step guide demonstrates PDF signing with certificate-based authentication.

Step 1: Create a new C# Console Application project

Begin by creating a new C# Console Application project in Visual Studio or your preferred IDE to implement PDF digital signature functionality.

Step 2: Install Syncfusion PDF NuGet package

Install the Syncfusion.Pdf.Net.Core NuGet package in your C# project from NuGet.org. This package provides the necessary APIs for PDF digital signature operations.

Step 3: Add required namespaces for PDF signing

Import the following namespaces in your Program.cs file to access PDF digital signature classes and methods:

using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

Step 4: Load the PDF document for digital signing

Use the PdfLoadedDocument class to load your existing PDF file and retrieve the page where you want to add the digital signature. This example signs the first page of the document.

//Load the PDF document.
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
    // Get the first page of the document
    PdfPageBase page = loadedDocument.Pages[0];
}

Step 5: Load the digital certificate (.pfx) for PDF signing

Use the PdfCertificate class to load your .pfx certificate file with its password. This certificate authenticates and secures your digital signature.

// Load the pfx file to sign the document
using FileStream certificate = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
PdfCertificate pdfCert = new PdfCertificate(certificate, "syncfusion");

Step 6: Create and configure the digital signature

Create a digital signature using the PdfSignature class with your certificate. Configure signature properties including bounds, signer name, contact information, location, and reason for signing.

Run

// Create a signature
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
// Set signature information
signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
signature.SignedName = "Syncfusion";
signature.ContactInfo = "[email protected]";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am the author of this document.";

Step 7: Customize the digital signature appearance

Customize your digital signature’s visual appearance using the Appearance property of the PdfSignature object. Add a signature image or custom graphics to display in the PDF.

// Load the image for the signature field
using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
PdfBitmap signatureImage = new PdfBitmap(imageStream);
// Draw the image on the signature field
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));

Step 8: Save the digitally signed PDF document

Save the digitally signed PDF document using the Save method. The output file will contain your certificate-based digital signature.

// Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));

NuGet installation

Nuget Installation image Syncfusion.Pdf.Net.Core Copy Icon image

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET PDF Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.