PdfDocumentSigner.SaveDocument(Stream, PdfSignatureBuilder[]) Method
Saves the PDF document to a stream with the specified document signatures.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Docs.v24.2.dll
NuGet Package: DevExpress.Document.Processor
#Declaration
public void SaveDocument(
Stream stream,
params PdfSignatureBuilder[] signatures
)
#Parameters
Name | Type | Description |
---|---|---|
stream | Stream | The stream to which to save the document. |
signatures | Pdf |
An array of signatures to apply to the document. |
#Remarks
Call the SaveDocument method to apply one or more signatures to the PDF document. Specify the document to be signed in the PdfDocumentSigner object’s constructor.
You can add a signature to the existing signature field. Create a new PdfSignatureBuilder object with the signature field’s name passed as the constructor’s parameter.
Use the PdfSignatureFieldInfo instance in the PdfSignatureBuilder object constructor to create a new signature field. You can specify the field’s name, bounds, and rotation angle.
The PDF Document API supports PKCS#7 signatures. The Pkcs7Signer class allows you to create this signature type. You can create a Pkcs7SignerBase descendant to use a custom object to create the PKCS#7 signature.
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);
}