officefileapi-devexpress-dot-pdf-69a06b68.md
Allows you to build a signature.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public class PdfSignatureBuilder
Public Class PdfSignatureBuilder
The PdfSignatureBuilder class allows you to apply a signature to a new or existing signature form field. You can sign documents that already contain a signature.
Use the newly created PdfSignatureBuilder object as the PdfDocumentSigner.SaveDocument method parameter to sign and save the target PDF document. Use an array of PdfSignatureBuilder objects to apply multiple signatures.
Use the IExternalSigner implementation to generate a signature. The PDF Document API supports the following signatures:
PKCS#7 signatures with x.509 certificatesYou can use the Pkcs7Signer class object as the constructor parameter to provide the PKCS#7 signature. Create the Pkcs7SignerBase class descendant to use a custom object to create the PKCS#7 signature. Pass the PdfSignatureProfile.PAdES_BES enumeration value to the object constructor to generate the PAdEs signature.Document-level timestampsThe PdfTimeStamp class object allows you to sign a form field with the document-level timestamp. Use the ITsaClient implementation to specify the timestamp client.
The PdfSignatureBuilder class properties allow you to specify the signer’s name, location, contact information, and the reason to apply the signature. Call the PdfSignatureBuilder.SetImageData method to specify the signature’s image.
Specify the PdfCertificationLevel property to define the changes available to users when the signature is applied. If a user makes a restricted change, the signature becomes invalid.
Pass the signature field name to the PdfSignatureBuilder object constructor to sign this form field.
using DevExpress.Pdf;
using DevExpress.Office.DigitalSignatures;
// Load a document to be signed
using (var signer = new PdfDocumentSigner("Document.pdf"))
{
// Create a PKCS#7 signature
Pkcs7Signer pkcs7Signature = new Pkcs7Signer("Signing Documents//testcert.pfx", "123", HashAlgorithmType.SHA256);
// Apply a signature to the Sign form field
var signatureBuilder = new PdfSignatureBuilder(pkcs7Signature, "Sign");
// Specify the signature's image and signer information:
signatureBuilder.SetImageData(System.IO.File.ReadAllBytes("Signing Documents//Jane Cooper.jpg"));
signatureBuilder.Location = "USA";
signatureBuilder.Name = "Jane Cooper";
signatureBuilder.Reason = "I Agree";
// Sign and save the document
signer.SaveDocument("SignedDocument.pdf", signatureBuilder);
}
Imports DevExpress.Pdf
Imports DevExpress.Office.DigitalSignatures
' Load a document to be signed
Using signer = New PdfDocumentSigner("Document.pdf")
' Create a PKCS#7 signature
Dim pkcs7Signature As New Pkcs7Signer("Signing Documents//testcert.pfx", "123", HashAlgorithmType.SHA256)
' Apply a signature to the Sign form field
Dim signatureBuilder = New PdfSignatureBuilder(pkcs7Signature, "Sign")
' Specify the signature's image and signer information:
signatureBuilder.SetImageData(System.IO.File.ReadAllBytes("Signing Documents//Jane Cooper.jpg"))
signatureBuilder.Location = "USA"
signatureBuilder.Name = "Jane Cooper"
signatureBuilder.Reason = "I Agree"
' Sign and save the document
signer.SaveDocument("SignedDocument.pdf", signatureBuilder)
End Using
If you create a new signature field, use the PdfSignatureFieldInfo object to specify the signature form field’s parameters (name, bounds, rotation angle, etc.). Pass the object to the PdfSignatureBuilder object constructor. Otherwise, the builder creates an invisible signature form field with a default name.
The code sample below creates and signs a new signature form field:
using DevExpress.Pdf;
using DevExpress.Office.DigitalSignatures;
/ /Load a document to be signed
using (var signer = new PdfDocumentSigner("SignedDocument.pdf"))
{
// Specify the name and location of the signature field
var description = new PdfSignatureFieldInfo(1);
description.Name = "SignatureField";
description.SignatureBounds = new PdfRectangle(10, 10, 150, 150);
// Create a PKCS#7 signature
Pkcs7Signer signature = new Pkcs7Signer("Signing Documents//testcert.pfx", "123", HashAlgorithmType.SHA256);
// Apply a signature to a new form field
var signatureBuilder = new PdfSignatureBuilder(signature, description);
// Specify the signature's image and signer information
signatureBuilder.SetImageData(System.IO.File.ReadAllBytes("Signing Documents//Signature.jpg"));
signatureBuilder.Location = "USA";
signatureBuilder.Name = "Jane Cooper";
// Sign and save the document
signer.SaveDocument("out2.pdf", signatureBuilder);
}
Imports DevExpress.Pdf
Imports DevExpress.Office.DigitalSignatures
' Load a document to be signed
Using signer = New PdfDocumentSigner("SignedDocument.pdf")
'Specify the name and location of the signature field
Dim description = New PdfSignatureFieldInfo(1)
description.Name = "SignatureField"
description.SignatureBounds = New PdfRectangle(10, 10, 150, 150)
'Create a PKCS#7 signature
Dim signature As Pkcs7Signer = New Pkcs7Signer("Signing Documents//testcert.pfx", "123", HashAlgorithmType.SHA256)
'Apply a signature to a new form field
Dim signatureBuilder = New PdfSignatureBuilder(signature, description)
'Specify the signature's image and signer information
signatureBuilder.SetImageData(System.IO.File.ReadAllBytes("Signing Documents//Signature.jpg"))
signatureBuilder.Location = "USA"
signatureBuilder.Name = "Jane Cooper"
'Sign and save the document
signer.SaveDocument("out2.pdf", signatureBuilder)
End Using
Object PdfSignatureBuilder PdfDeferredSignatureBuilder
See Also