Interactive Forms

AcroForm API

The Form class, accessible via Document.getForm(), manages all AcroForm fields in the document. Fields are added by calling Form.add(field, pageNumber).

RadioButtonField

Create a group of radio buttons, each option at its own Rectangle:

try (Document doc = new Document()) {
    Page page = doc.getPages().add();
    RadioButtonField radio = new RadioButtonField(page);
    radio.setPartialName("color");
    radio.addOption("Red", new Rectangle(50, 50, 70, 70));
    radio.addOption("Blue", new Rectangle(50, 80, 70, 100));
    doc.getForm().add(radio, 1);
    radio.setValue("Red");
    doc.save("form.pdf");
}

setValue() selects an option programmatically. getValue() returns the currently selected option name.

CheckboxField

CheckboxField provides a single boolean toggle at a specified rectangle position:

CheckboxField cb = new CheckboxField(page, new Rectangle(100, 100, 120, 120));
cb.setPartialName("agree");
cb.setChecked(true);
doc.getForm().add(cb, 1);

TextBoxField

TextBoxField accepts freeform text input:

TextBoxField text = new TextBoxField(page, new Rectangle(50, 200, 250, 220));
text.setPartialName("name");
text.setValue("Default text");
doc.getForm().add(text, 1);

ComboBoxField and ListBoxField

ComboBoxField and ListBoxField provide dropdown and scrollable list controls. Both accept option strings via addOption().

FormEditor

FormEditor provides convenience methods for bulk operations across existing form fields in a bound document.

See Also