Filling a PDF AcroForm
Use DynamicPDF Core Suite for .NET to fill in the fields of a PDF AcroForm programmatically and reorganize fields by appending name prefixes when merging a PDF using DynamicPDF Core Suite for .NET. The following examples illustrate filling and reorganizing an AcroForm.
Watch the Video
How to Fill AcroForm
The following steps and C# sample code illustrate how to fill a PDF AcroForm programmatically using DynamicPDF Core Suite for .NET.
Steps for Filling an AcroForm
- Create a new
MergeDocument
instance. - Set the field values by specifying the field name and the desired value.
- Add the
Draw
method to output the PDF document.
Sample Code - C#
MergeDocument document = new MergeDocument(Util.GetPath("Resources/PDFs/fw9AcroForm_18.pdf"));
document.Form.Fields["topmostSubform[0].Page1[0].f1_1[0]"].Value = "Any Company, Inc.";
document.Form.Fields["topmostSubform[0].Page1[0].f1_2[0]"].Value = "Any Company";
document.Form.Fields["topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]"].Value = "1";
document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_7[0]"].Value = "123 Main Street";
document.Form.Fields["topmostSubform[0].Page1[0].Address[0].f1_8[0]"].Value = "Washington, DC 22222";
document.Form.Fields["topmostSubform[0].Page1[0].f1_9[0]"].Value = "Any Requester";
document.Form.Fields["topmostSubform[0].Page1[0].f1_10[0]"].Value = "17288825617";
document.Draw("output.pdf");
How to Reorganize and Fill AcroForm
The following steps and C# sample code illustrate using DynamicPDF Core Suite for .NET to merge two PDF documents containing AcroForms and then reorganizing the combined AcroForm field names with name prefixes.
Steps for Reorganizing and Filling an AcroForm
- Create a
MergeDocument
instance, and in the constructor, specify aMergeOptions
instance that specifies a prefix for its form fields. - Append a second PDF document to the
MergeDocument
instance and specify aMergeOptions
instance that specifies a prefix for its form fields (unique from the previous form's prefix). - Set the field values using the new unique names (prefix and original names).
- Add the
Draw
method to output the PDF document.
Sample Code - C#
MergeDocument document = new MergeDocument("fw9AcroForm_18.pdf"), new MergeOptions(true, "fw_9A"));
document.Append("fw9AcroForm_18.pdf"), new MergeOptions(true, "fw_9B"));
document.Form.Fields["fw_9A.topmostSubform[0].Page1[0].f1_1[0]"].Value = "Any Company A, Inc.";
document.Form.Fields["fw_9A.topmostSubform[0].Page1[0].f1_2[0]"].Value = "Any Company A";
document.Form.Fields["fw_9B.topmostSubform[0].Page1[0].f1_1[0]"].Value = "Any Company B, Inc.";
document.Form.Fields["fw_9B.topmostSubform[0].Page1[0].f1_2[0]"].Value = "Any Company B";
document.Draw("output.pdf");
GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - FieldNamesExample.cs
- VB.NET - FieldNamesExample.vb
- C# - AcroFormFilling.cs
- VB.NET - AcroFormFilling.vb
- C# - AcroFormFillingMerge.cs
- VB.NET - AcroFormFillingMerge.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite for .NET Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Filling AcroForms
- Refer to the AcroForms Overview, or
- Chapter 24, Modifying Forms, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX