Understanding the form fields object structure

Introduction

Form fields are dynamic elements similar to HTML form fields: they provide an easy way to update PDF contents without the need to regenerate the whole document.

There are currently seven different types of form fields defined for PDF documents, each associated with a given class in the jpdf packages:

  1. TextField
  2. CheckBoxField
  3. RadioButtonField
  4. ComboBoxField
  5. ListBoxField
  6. ButtonField
  7. SignatureField

Implementation

The implementation of form fields in the API is presented in the image below.

As with HTML form fields, PDF form fields have two main properties:

  1. a name: Apart from special situations, each form field is uniqualy identified by its name in a PDF document.
  2. a value: The current value of a form field.

Implementation

Accessing existing form fields via the API will always be done via the template module - as follows:

// Load the template module:
TemplateModule template = doc.getTemplateModule(); 

// Recover the form field named "Text":
AbstractField myField= template.getField("Text");

Upon modification of the form fields' values or attributes (see How to fill form fields), the API will update the internal structure of the form fields and, depending on the appearance generation setup (see Appearance generation), will also generate a visual representation of the new form field state.