# Tutorial: iText by Example

## Interactive Forms

UNDER CONSTRUCTION
Acroform:
Extract from the Portable Document Format Reference Manual Version 1.6 (section 8.6 'Interactive Forms' page 634):

> An interactive form (PDF 1.2)–sometimes referred to as an Acroform–is a collection of fields for gathering information interactively from the user. A PDF document may contain any number of fields appearing on any combination of pages, all of which make up a single, global interactive form spanning the entire document.

Do not confuse Acroforms with HTML forms (<form>-tags). They share some of the same purposes (e.g. getting userdata in an interactive way), but they are completely different. You can't have more than one form in a PDF document. Fields in an acroform can be organized hierarchically and can inherit attributes from their ancestors in the field hierarchy. Each field has a name (See the Portable Document Format Reference Manual Version 1.6 section 8.6.2 'Field Dictionaries' page 638):

> The fully qualified filed name is not explicitly defined but is constructed from the partial field names of the field and all of its ancestors. For a field with no parent, the partial and fully qualified names are the same. For a field that is the child of another field, the fully qualified name is formed by appending the child field's partial name to the parent's fully qualified name, separated by a period (.):

>       parent's_full_name.child's_partial_name

> For example, if a field with the partial field name PersonalData has a child whose partial name is Address, which in turn has a child with the partial name ZipCode, the fully qualified name of this last field is

>     PersonalData.Address.ZipCode

> Thus, all fields descended from a common ancestor share the ancestor's fully qualified field name as a common prefix in their own filly qualified names.

Go to top of the page
Field types:
The Portable Document Format Reference Manual Version 1.6 (section 8.6.3 'Field Types' page 647) distinguishes four types of fields:

1. Btn: Button Fields
2. Tx: Text Fields
3. Ch: Choice
4. Sig: Signature

Button Fields

> Button fields represent interactive controls on the screen that the user can manipulate with the mouse. They include pushbuttons, check boxes, and radio buttons.

You can create all these button fields with the methods PdfFormField.createPushButton(PdfWriter writer), PdfFormField.createCheckBox(PdfWriter writer) and/or PdfFormField.getRadioButton(PdfWriter writer, boolean noToggleToOff). You are going to create a PdfAppearance for every mouse operation:

- PdfAnnotation.APPEARANCE_NORMAL: the normal appearance (no mouse action)
- PdfAnnotation.APPEARANCE_ROLLOVER: the appearance when the mouse is pointed at the button (mouseover)
- PdfAnnotation.APPEARANCE_APPEARANCE_DOWN: the appearance when the button is pushed down

Remark: the syntax to create this appearance is the same as for PdfContentByte as described in Part IV of the tutorial. To visualize the button, you will set its widget annotations with setWidget(Rectangle rect, PdfName highlight). Parameter rect defines the position on the page, highlight is one of the following values:

- PdfAnnotation.HIGHLIGHT_NONE: no highlighting.
- PdfAnnotation.HIGHLIGHT_INVERT: invert the contents of the highlighted field.
- PdfAnnotation.HIGHLIGHT_OUTLINE: invert the border of the field.
- PdfAnnotation.HIGHLIGHT_PUSH: Display the down appearance, if any. If no down appearance is defined, offset the contents of the annotation rectangle to appear as if it were being pushed below the surface of the page.
- PdfAnnotation.HIGHLIGHT_TOGGLE: Same as PdfAnnotation.HIGHLIGHT_PUSH (which is preferred).

Example: java com.lowagie.examples.forms.FormPushButton
Generates a PDF with an Acroform containing a pushbutton: see pushbutton.pdf
Example: java com.lowagie.examples.forms.FormCheckbox
Generates a PDF with an Acroform containing a checkbox: see checkbox.pdf
Example: java com.lowagie.examples.forms.FormRadioButton
Generates a PDF with an Acroform containing a radiobutton: see radiobutton.pdf
Text Fields

> Text fields are boxes or spaces in which the user can enter text from the keyboard.

TextField
Example: java com.lowagie.examples.forms.FormTextField
Generates a PDF with an Acroform containing a text field: see textfield.pdf
Example: java com.lowagie.examples.forms.SimpleRegistrationForm
Generates a PdfPTable with some TextFields: see SimpleRegistrationForm.pdf
Choice

> Choice fields contain several text items, at most one of which may be selected as the field value. They include scrollable list boxes and combo boxes.

Example: java com.lowagie.examples.forms.FormList
Generates a PDF with an Acroform containing a list: see list.pdf
Example: java com.lowagie.examples.forms.FormCombo
Generates a PDF with an Acroform containing a combobox: see combo.pdf
Example: java com.lowagie.examples.forms.TextFields
Generates a PDF with an Acroform containing text fields: see TextFields.pdf
Signature

> Signature fields represent electronic signatures for authenticating the identity of a user and the validity of the document’s contents.

Example: java com.lowagie.examples.forms.FormSignature
Generates a PDF with an Acroform containing a signature: see signature.pdf
Go to top of the page
Amazon books:
amazon.co.uk-link