Skip to content

Add a signature field to a PDF in C#

Since 1.1View as Markdown

Place an empty signature box on a page for someone to sign later in their PDF viewer.

Call doc.Form.AddSignatureField with the page, a field name and the box position and size, measured from the page’s top left corner in points. PdfFieldOptions sets the border, background and tooltip.

recipe-add-signature-field.cs
#:package PdfNetStack@1.2.0
using PdfNetStack;
using PdfNetStack.Drawing;
PdfDocument doc = PdfDocument.Open("contract.pdf");
PdfPage last = doc.Pages[^1];
doc.Form.AddSignatureField(last, "signature", 72, 730, 220, 60, new PdfFieldOptions
{
BorderColor = PdfColor.Gray(0.5),
ToolTip = "Sign here",
});
doc.Save("contract-to-sign.pdf");
Console.WriteLine(string.Join(", ", PdfDocument.Open("contract-to-sign.pdf").Form.Fields.Select(f => $"{f.Name} ({f.Kind})")));

To sign in code instead, use PdfSigner.Sign. It adds its own signature field, with an optional visible appearance, in an incremental update, and does not fill an existing empty field. See Signatures.