officefileapi-devexpress-dot-pdf-a5305058.md
A helper class used to apply signatures to PDF documents.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Docs.v25.2.dll
NuGet Package : DevExpress.Document.Processor
[DXLicenseDocs]
public class PdfDocumentSigner :
IDisposable
<DXLicenseDocs>
Public Class PdfDocumentSigner
Implements IDisposable
Use the PdfDocumentSigner instance to apply signatures to new or existing signature fields. Call the PdfDocumentSigner.SaveDocument method to sign and save the PDF document.
The PdfSignatureBuilder class allows you to define signature data. The PDF Document API supports PKCS#7 signatures. You can use the Pkcs7Signer class to provide PKCS#7 signatures. Create a Pkcs7SignerBase descendant to use a custom object to create the PKCS#7 signature.
The following code snippet executes the following actions:
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"))
{
// Specify the name and location of the signature field
var signatureFieldInfo = new PdfSignatureFieldInfo(1);
signatureFieldInfo.Name = "SignatureField";
signatureFieldInfo.SignatureBounds = new PdfRectangle(20, 20, 150, 150);
signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90;
// 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);
}
Imports System
Imports DevExpress.Pdf
Imports System.Diagnostics
Imports System.IO
Imports DevExpress.Office.DigitalSignatures
' Load a document to sign:
Using signer = New PdfDocumentSigner("Document.pdf")
'Specify the name and location of the signature field
Dim signatureFieldInfo = New PdfSignatureFieldInfo(1)
signatureFieldInfo.Name = "SignatureField"
signatureFieldInfo.SignatureBounds = New PdfRectangle(20, 20, 150, 150)
signatureFieldInfo.RotationAngle = PdfAcroFormFieldRotation.Rotate90
' Create a PKCS#7 signature:
Dim pkcs7Signature As New Pkcs7Signer("Signing Documents/certificate.pfx", "123",
HashAlgorithmType.SHA256)
' Apply a signature to a newly created signature field:
Dim 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:
Dim 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:
Dim signatures() As PdfSignatureBuilder = { cooperSignature, santuzzaSignature }
' Sign and save the document:
signer.SaveDocument("SignedDocument.pdf", signatures)
End Using
Object PdfDocumentSigner
See Also