Skip to main content

Work with PDF Forms (AcroForms)

  • 2 minutes to read

PDF documents can contain interactive forms (AcroForms). An AcroForm consists of one or more form fields that allow users to enter or select data. Common field types include text boxes, check boxes, radio button groups, list boxes, combo boxes, and signature fields.

The PDF Document API allows you to:

  • Create interactive PDF forms.
  • Read and modify form fields.
  • Import and export form data.
  • Group form fields.
  • Flatten the form field hierarchy.
  • Configure field formatting and validation.

Supported Form Field Types

The PDF Document API supports the following AcroForm field types:

AcroForm Object Model

An AcroForm consists of the following elements:

Form field
A non-visual object that stores a field’s name, value, and behavior.
Widget annotation
Defines how the field appears on a page and where users interact with it.

A form field can have one or more widget annotations. This structure allows the same field value to appear in multiple locations in a document.

PdfDocument
    └── Fields
            └── FormField
                    ├── Name
                    ├── Value
                    └── Widget Annotation(s)
                                ├── Location
                                ├── Size
                                └── Appearance

Access Form Fields

Use the PdfDocument.getFields() method to access the collection of form fields in a PDF document.

The following code snippet iterates through all form fields and prints their names and types:

// Iterate through all form fields in the document, including grouped fields.
for (FormField field : pdfDocument.getFields().toFlatIterable()) {
    System.out.println(field.getName());
    System.out.println(field.getClass().getSimpleName());
}

Refer to the following help topic for additional information: Access and Find PDF Form Fields.

Nest Steps

See Also