Click or drag to resize
Pdf Library for .NET

Form Filling

SelectPdf can be used to open existing PDF documents that contain AcroForms form fields, get information about the form fields (name, type, value, status) fill the form fields and change some of their properties (like read-only or flatten).

This can be done using PdfFormManager object. Using it, the list of fields can be accessed through the Fields property. The following types of fields can be handled by SelectPdf:

For all form fields, the following properties can be accessed:

  • Name - Gets or sets the name of the field.

  • FullName - Gets the fully-qualified field name (parent-qualified for nested fields). Use this when the field name in the PDF is qualified (for example address.city).

  • DisplayPage - Gets the zero-based index of the page on which the field is displayed.

  • DisplayRectangle - Gets the bounds of the field on its page as a RectangleF.

  • Widgets - Gets the collection of widget annotations that represent the field on the page. A single form field can have more than one widget (for example a check box repeated in the header and footer).

  • ReadOnly - Gets or sets a value indicating whether the field is read-only or not.

  • Flatten - Gets or sets a value indicating whether to flatten this form field or not.

When a check box field has multiple widgets that represent the same logical value on different pages, each widget can be read or written individually through GetWidgetCheckedValue(Int32) and SetWidgetCheckedValue(Boolean, Int32), where the integer is the widget index in the Widgets collection. Setting Checked applies to every widget at once.

The whole PDF form can be marked as read-only or flattened using the properties ReadOnly or Flatten.

Starting with version 21.1 of SelectPdf, a new PDF forms engine was introduced with SelectPdf.Extras package. To use it, SelectPdfPdfFormManager needs to be replaced with SelectPdf.FormsPdfFormManager.

Code Sample
// load the pdf form manager
PdfFormManager form = new PdfFormManager();
form.Load(file);

// fill some fields
PdfFormFieldTextBox txtField = form.Fields["textfieldname"] as PdfFormFieldTextBox;
txtField.Text = "Some text";

PdfFormFieldCheckBox chkField = form.Fields["checkboxfieldname"] as PdfFormFieldCheckBox;
chkField.Checked = true;

// save pdf document
form.Save("Sample.pdf");

// close pdf document
form.Close();
See Also