Skip to main content
A newer version of this page is available. .
.NET Standard 2.0+

PdfSignature Class

An electronic signature used to sign a PDF file.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v19.1.Core.dll

Declaration

public class PdfSignature :
    PdfObject

Remarks

A signature is represented by an instance of the PdfSignature class with the specified certificate. A visual signature can be created using one of the PdfSignature constructors that takes 4 arguments. For example, using a certificate, image data represented by a byte array, the page number and signature bounds. The signature bounds can be specified using a PdfOrientedRectangle object. You can also specify the rotation angle for the signature (in radians) when creating a PdfOrientedRectangle object. A positive angle means counterclockwise rotation; a negative angle means clockwise rotation.


//...
X509Certificate2 certificate = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo");              
byte[] imageData = File.ReadAllBytes("..\\..\\Signature.png");
int pageNumber = 1;
int angleInDegrees = 45; 
double angleInRadians = angleInDegrees * (Math.PI / 180);
PdfOrientedRectangle signatureBounds = new PdfOrientedRectangle(new PdfPoint(0, 460), 250, 90, angleInRadians);
PdfSignature signature = new PdfSignature(certificate, imageData, pageNumber, signatureBounds);

When a signature is created, you can specify a signing PdfSignature.Name, PdfSignature.Reason, PdfSignature.Location, PdfSignature.ContactInfo, and PdfSignature.SigningTime.

To save a document with signing information, pass a PdfSaveOptions object as a parameter with a signature to the PdfDocumentProcessor.SaveDocument method.

Use the PdfSaveOptions.Signature property to access a PdfSignature object,

Example

This example illustrates how to add a visual signature to a PDF document.

To accomplish this task, do the following:

using DevExpress.Pdf;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace PDFSignature {
    class Program {
        static void Main(string[] args) {

            // Create a PDF document processor.
            using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {

                // Load a PDF document. 
                documentProcessor.LoadDocument(@"..\..\Demo.pdf");

                // Create a visual signature using certificate, image data, and specifying  page number, signature bounds and rotation angle. 
                X509Certificate2 certificate = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo");
                byte[] imageData = File.ReadAllBytes("..\\..\\Signature.png");
                int pageNumber = 1;
                int angleInDegrees = 45; 
                double angleInRadians = angleInDegrees * (Math.PI / 180);
                PdfOrientedRectangle signatureBounds = new PdfOrientedRectangle(new PdfPoint(620, 210), 250, 90, angleInRadians);
                PdfSignature signature = new PdfSignature(certificate, imageData, pageNumber, signatureBounds);

                // Specify signing location, contact info and reason.
                signature.Location = "USA";
                signature.ContactInfo = "john.smith@example.com";
                signature.Reason = "Approved";

                // Save the signed document.
                documentProcessor.SaveDocument(@"..\..\SignedDocument.pdf", new PdfSaveOptions() { Signature = signature });
            }
        }
    }
}

Inheritance

Object
DevExpress.Pdf.Native.PdfDocumentItem
DevExpress.Pdf.Native.PdfObject
PdfSignature
See Also