Guide
How to sign a PDF form field in C#
Use SignatureFormField.SignAsync(...) with an X509Certificate2 that contains a
private key. ZingPDF writes a detached CMS signature into the PDF.
Use the field API when the document already contains a signature field. Use
Pdf.SignInvisibleAsync(...) when you only need cryptographic validation and want to add a
hidden signature field automatically.
Signed output is saved as a rewritten file so the final byte ranges stay stable for validators.
Sign an existing signature field
Look up the field, call SignAsync(...), and save the PDF.
using System.Security.Cryptography.X509Certificates;
using ZingPDF;
using ZingPDF.Elements.Forms.FieldTypes.Signature;
using var pdf = Pdf.Load(File.OpenRead("approval-form.pdf"));
using var certificate = new X509Certificate2("signing-cert.pfx", "pfx-password");
var form = await pdf.GetFormAsync();
var signatureField = await form!.GetFieldAsync<SignatureFormField>("ApprovalSignature");
await signatureField!.SignAsync(certificate, new PdfSignatureOptions
{
SignerName = "Taylor Smith",
Reason = "Approved"
});
await pdf.SaveAsync(File.Create("signed.pdf"));
Add a signature image
Set SignatureImageBytes when the visible appearance should include a logo, stamp, or scanned
signature image alongside the signature text.
await signatureField!.SignAsync(certificate, new PdfSignatureOptions
{
SignerName = "Taylor Smith",
Reason = "Approved",
SignatureImageBytes = File.ReadAllBytes("signature-stamp.png")
});
Sign without an existing field
For validation-only workflows, add a hidden signature field and sign it in one step.
using System.Security.Cryptography.X509Certificates;
using ZingPDF;
using var pdf = Pdf.Load(File.OpenRead("statement.pdf"));
using var certificate = new X509Certificate2("signing-cert.pfx", "pfx-password");
await pdf.SignInvisibleAsync(certificate, new PdfSignatureOptions
{
FieldName = "ServerSignature",
SignerName = "Taylor Smith",
Reason = "Integrity check"
});
await pdf.SaveAsync(File.Create("statement-signed.pdf"));
This path creates a hidden signature field on the document, so the signature is present for validators even though there is no visible stamp on the page.
The certificate must include a private key
ZingPDF signs through X509Certificate2, so the certificate you pass in must have a private key
available at runtime. A public certificate on its own is not enough.
Add signer metadata when you need it
PdfSignatureOptions lets you set signer name, reason, location, contact info, and signing
time. Those values are written into the signature dictionary alongside the detached CMS payload.
Current limits
High-level signing supports existing signature fields and hidden validation-only fields on unencrypted PDFs. It does not sign encrypted PDFs yet, and it does not create visible signature fields automatically.
Need to fill the form first?
Fill the rest of the AcroForm fields before signing.