Form Filling

DynamicPDF Core Suite supports working with AcroForms while merging. A form can have its values completed programmatically one at a time, its field values reorganized, or complete a form's values using an FDF file.

Refer to the Interactive Forms topic for documentation on creating a form.

AcroForm Filling

AcroForm field values are set as they are merged into a new PDF document. Obtain the form fields using a MergeDocument instance's Form property. The existing document is read into the MergeDocument instance, the form field values are completed, and then the document is saved as a new document.

After completing a form, the document is flattened. You cannot modify a form after being completed.


AcroForm fields are merged using the Form property of the MergeDocument class. The Form property - inherited from the Document class - has a Fields property, a FormFieldList that contains the FormField instances. The FormFieldList contains zero or more FormField instances. A Form instance uses the Value property to obtain the FormField instance's value.

Unicode values are fully supported. When completing a form programmatically, the specified value must match the export value for the form field. The following example illustrates setting AcroForm's values.

MergeDocument document = new MergeDocument( pdfFilePath );
// Set the field values
document.Form.Fields["TextBox1"].Value = "My Text"; // TextBox field
document.Form.Fields["CheckBox1"].Value = "Yes"; // CheckBox field
document.Form.Fields["ComboBox1"].Value = "Item4"; // ComboBox field
document.Form.Fields["RadioButton1"].Value = "Item2"; // RadioButton field
ListBoxField listBox = (ListBoxField) document.Form.Fields["ListBox1"]; // ListBox field
listBox.SetValues( new string[] { "Item1", "Item3", "Item5" } );
// Save the PDF
Dim MyDocument As MergeDocument = New MergeDocument( pdfFilePath )
' Set the field values
MyDocument.Form.Fields("TextBox1").Value = "My Text" ' TextBox field
MyDocument.Form.Fields("CheckBox1").Value = "Yes" ' CheckBox field
MyDocument.Form.Fields("ComboBox1").Value = "Item4" ' ComboBox field
MyDocument.Form.Fields("RadioButton1").Value = "Item2" ' RadioButton field
Dim MyListBox As ListBoxField = CType( MyDocument.Form.Fields("ListBox1"), ListBoxField) ' ListBox field
MyListBox.SetValues(New String() {"Item1", "Item3", "Item5"})
' Save the PDF

Filling Reorganized Acro Form Fields

You can reorganize AcroForm fields as they are being merged. This reorganization prevents renaming issues and helps organize form field data. The following example illustrates merging two PDF documents containing AcroForm fields and reorganizing their names.

MergeDocument document = new MergeDocument( pdfFilePath, new MergeOptions( true, "fw_4" ) );
document.Append( pdfFilePath, new MergeOptions( true, "fw_9" ) );
// Set the field values
document.Form.Fields["fw_4.FirstName"].Value = "John";
document.Form.Fields["fw_9.FirstName"].Value = "John";
// Save the PDF
Dim MyDocument As MergeDocument = New MergeDocument( pdfFilePath, New MergeOptions( True, "fw_4" ) )
MyDocument.Append( pdfFilePath, New MergeOptions( True, "fw_9" ) )
' Set the field values
MyDocument.Form.Fields("fw_4.FirstName").Value = "John"
MyDocument.Form.Fields("fw_9.FirstName").Value = "John"
' Save the PDF

In the previous example, both forms have a FirstName field. To prevent a naming collision, the AcroForm field in the first document prepends an fw_4. to the field name while the second document prepends an fw_9. to its field name.

Form Filing using FDF files

An FDF file is a text file format used for data exported from PDF form fields that contain only form field data, not a complete form. An AcroForm's fields can be completed using an FDF file through the ImportFormDataAction class. The following example illustrates using an FDF file.

MergeDocument document = new MergeDocument(@"OutputPDF.pdf");
document.Pages[0].ReaderEvents.Open = new ImportFormDataAction("FDF file path");
Dim MyDocument As MergeDocument = New MergeDocument("OutputPDF.pdf")
MyDocument.Pages(0).ReaderEvents.Open = New ImportFormDataAction("FDF file path")

Refer to the ImportFormDataAction API documentation for a complete example.

In this topic