Form Filling

As PDF documents are created, DynamicPDF supports merging form field values using acro form field values, reorganized acro form fields, and FDF files.

AcroForm Filling

Acro form field values are set as they are merged into a new PDF document. This is done through the Form property of the MergeDocument class.

The specified value must match the export value for the form field. Unicode values are fully supported. The following example illustrates setting the values on a merged Acro form.

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 Acro form fields as they are merged into a PDF document. This reorganization prevents renaming issues and helps organize form field data. The following example illustrates merging two PDF documents containing Acro form 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

NOTE: In the previous example, the Acro form fields in the first document will contain a "fw_4." prepended to their name, and the Acro form fields in the second document will contain "fw_9." prepended to their names.

Form Filing using FDF files

The Acro form fields can be filled using FDF files using the ImportFormDataAction class.

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")

In this topic