Back to Devexpress

PdfDocumentSigner.SaveDocument(String, PdfSignatureBuilder[]) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentsigner-dot-savedocument-x28-system-dot-string-devexpress-dot-pdf-dot-pdfsignaturebuilder-x29.md

latest7.6 KB
Original Source

PdfDocumentSigner.SaveDocument(String, PdfSignatureBuilder[]) Method

SECURITY-RELATED CONSIDERATIONS

Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.

Saves the PDF document to a file with the specified document signatures.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void SaveDocument(
    string filePath,
    params PdfSignatureBuilder[] signatures
)
vb
Public Sub SaveDocument(
    filePath As String,
    ParamArray signatures As PdfSignatureBuilder()
)

Parameters

NameTypeDescription
filePathString

The path to a file into which to save the document.

| | signatures | PdfSignatureBuilder[] |

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. Use the Pkcs7Signer class to create this signature type. You can create a Pkcs7SignerBase descendant to use a custom object to create the PKCS#7 signature.

csharp
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);
}
vb
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

The following code snippets (auto-collected from DevExpress Examples) contain references to the SaveDocument(String, PdfSignatureBuilder[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-custom-signer/CS/CustomSigner/Program.cs#L34

csharp
//Sign and save the document:
signer.SaveDocument("SignedDocument.pdf", signatureBuilder);
Process.Start(new ProcessStartInfo("SignedDocument.pdf") { UseShellExecute = true}) ;

pdf-document-api-custom-tsa-client/CS/CustomTsaClient/Program.cs#L31

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

pdf-document-api-sign-documents-with-certificate/CS/SignPDFWithHardwareCertificate/Program.cs#L62

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

pdf-document-api-custom-signer/VB/CustomSigner/Program.vb#L34

vb
'Sign and save the document:
signer.SaveDocument("SignedDocument.pdf", signatureBuilder)
Process.Start(New ProcessStartInfo("SignedDocument.pdf") With {.UseShellExecute = True})

pdf-document-api-custom-tsa-client/VB/CustomTsaClient/Program.vb#L29

vb
'Sign and save the document:
signer.SaveDocument("SignedDocument.pdf", signatureBuilder)

pdf-document-api-use-azure-key-vault-api-to-sign-document/VB/PdfAPIAzureKeyVaultSample/Program.vb#L52

vb
Dim output As String = "SignedDocument.pdf"
signer.SaveDocument(output, signatureBuilder)
Process.Start(New ProcessStartInfo(output) With {.UseShellExecute = True})

pdf-document-api-sign-documents-with-certificate/VB/SignPDFWithHardwareCertificate/Program.vb#L48

vb
' Sign and save the document
    signer.SaveDocument("SignedDocument.pdf", cooperSignature)
End Using

See Also

PdfDocumentSigner Class

PdfDocumentSigner Members

DevExpress.Pdf Namespace