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:
Textbox using PdfFormFieldTextBox. For a textbox field, the field value can be set using the property Text.
Checkbox using PdfFormFieldCheckBox. For a checkbox field, the checked status can be set or unset using the property Checked.
Listbox using PdfFormFieldListBox. For a list box field, the selected items can be set using either property SelectedIndexes or SelectedValues. The number of items in the list can be obtained using ItemsCount property. The list of items from the listbox can be accessed using the Items property. MultiSelect can be used to determine if more than 1 item can be selected from the list box.
Combo box using PdfFormFieldComboBox. For a combo box field, the selected item can be set using either property SelectedIndex or SelectedValue. The number of items in the list can be obtained using ItemsCount property. The list of items from the combo box can be accessed using the Items property.
Radio buttons list using PdfFormFieldRadioButtonList. For a radio buttons list field, the selected item can be set using either property SelectedIndex or SelectedValue. The number of items in the list can be obtained using ItemsCount property. The list of items can be accessed using the Items property.
For all form fields, the following properties can be accessed:
Name - Gets or sets the name of the field.
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.
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.
// 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();