How to add a signature field to an existing PDF document using C#
The Syncfusion Essential® PDF is a comprehensive, high-performance .NET PDF library that enables developers to create, read, and modify PDF documents programmatically without relying on Adobe components. It provides advanced features such as merging, splitting, stamping, form handling, compression, and securing PDF files. Using this library, you can easily add a signature field to an existing PDF document.
Steps to add a signature field to an existing PDF document programmatically
- Create a new project: Start a new console application in .NET core.
- Install required packages: Add the Syncfusion.Pdf.Net.Core NuGet package to your project.
- Include namespaces: In your
Program.csfile, include the essential namespaces.
C#
using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Drawing;
- Implement main logic: Use the provided code sample in
Program.csto add a signature field to an existing PDF document.
C#
// Load the existing PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
{
// Ensure the document has a form; create one if it doesn't exist
if (loadedDocument.Form == null)
loadedDocument.CreateForm();
// Load the first page of the PDF
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
// Create a new PDF signature field on the loaded page
PdfSignatureField signatureField = new PdfSignatureField(loadedPage, "Signature");
// Set properties for the signature field (position and tooltip)
signatureField.Bounds = new RectangleF(100, 300, 90, 20);
signatureField.ToolTip = "Signature";
// Add the signature field to the form in the existing document
loadedDocument.Form.Fields.Add(signatureField);
// Save the PDF document
loadedDocument.Save("Output.pdf");
}
A complete working sample is available for download from GitHub.
By executing the program, you will generate the following PDF document.
Take a moment to peruse the documentation to learn how to add a digital signature field to a PDF document.
Conclusion
I hope you enjoyed learning how to add a signature field to an existing PDF document.
You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!