Add Digital Signature to PDF via C#

Digital signature generation and verification using server-side Aspose.PDF for .NET APIs. Native and high performance library

How to add Digitally Sign to PDF File Using .NET Library

In order to add digital signature in PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Add Digitally Sign to PDF via C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Load all the PDF files with full path.
  3. Set the style of text like font, font size, color etc.
  4. Save PDF file, You will get the document with signature inserted.
  5. To verify the validity of the signature use PdfFileSignature.VerifySigned() method.

Add Electronic Signature to a PDF File using - C#

This sample code shows how to Signature PDF Pages - C#

Input file:

File not added

Certificate file:

File not added

Output format:

Output file:

public static void SignDocument()
{
    string inFile = System.IO.Path.Combine(_dataDir,"DigitallySign.pdf");
    string outFile = System.IO.Path.Combine(_dataDir,"DigitallySign_out.pdf");
    using (Document document = new Document(inFile))
    {
        using (PdfFileSignature signature = new PdfFileSignature(document))
        {
            PKCS7 pkcs = new PKCS7(@"C:\Keys\test.pfx", "Pa$$w0rd2020"); // Use PKCS7/PKCS7Detached objects
            signature.Sign(1, true, new System.Drawing.Rectangle(300, 100, 400, 200),pkcs);
            // Save output PDF file
            signature.Save(outFile);
        }
    }
}