Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Sign a PDF File with a Certificate Stored in a .PFX File

  • 2 minutes to read

The PdfDocumentSigner class allows you to sign and save a document. Use the PdfSignatureBuilder class to apply a signature to a form field. The PDF Document API supports PKCS#7 signatures with X.509 certificates. You can use a certificate stored in a .PFX file.

The code sample below shows how to create a PKCS#7 signature with a certificate stored in a .PFX file, applies a digital signature to a new and existing form field, and signs a document with these signatures:

View Example: How to Apply Multiple Signatures

using System;
using DevExpress.Pdf;
using System.Diagnostics;
using System.IO;
using DevExpress.Office.DigitalSignatures;

// Load a document to sign:
using (var signer = new PdfDocumentSigner("Document.pdf"))
{

    // Create a PKCS#7 signature:
    Pkcs7Signer pkcs7Signature = new Pkcs7Signer("Signing Documents/certificate.pfx", "123", 
        HashAlgorithmType.SHA256);

    // Apply a signature to a newly created signature field:
    var cooperSignature = new PdfSignatureBuilder(pkcs7Signature, signatureFieldInfo);

    // Specify an image and signer information:
    cooperSignature.SetImageData(File.ReadAllBytes("Signing Documents//JaneCooper.jpg"));
    cooperSignature.Location = "USA";
    cooperSignature.Name = "Jane Cooper";
    cooperSignature.Reason = "Acknowledgement";

    // Apply a signature to an existing form field:
    var santuzzaSignature = new PdfSignatureBuilder(pkcs7Signature, "Sign");

    // Specify an image and signer information:
    santuzzaSignature.SetImageData(File.ReadAllBytes("Signing Documents//SantuzzaValentina.jpg"));
    santuzzaSignature.Location = "Australia";
    santuzzaSignature.Name = "Santuzza Valentina";
    santuzzaSignature.Reason = "I Agree";

    // Add signatures to an array:
    PdfSignatureBuilder[] signatures = { cooperSignature, santuzzaSignature };

    // Sign and save the document:
    signer.SaveDocument("SignedDocument.pdf", signatures);
}