Forms
The publisher creates fillable PDF forms: text fields, check boxes, radio buttons and choice fields. The recipient fills in the PDF in an ordinary PDF viewer, saves it and sends it back. The values can then be read out automatically with tools such as pdfcpu or pdftk.
The advantage over a form built by hand lies in the data: fields are prefilled from the data, their number follows the data (one row per article), and the field names can be chosen so that the returned values can be assigned to the records again. A complete example with evaluation is shown in the recipe Order form from the data.
Kinds of fields
All fields are created with <Formfield>, the kind is set with type:
type | Field | Value in the form data |
|---|---|---|
text (default) | Text field, with multiline="yes" with several lines | the text entered |
checkbox | Check box | value (default Yes) or Off |
radio | Radio button; buttons with the same name form a group | value of the selected button or Off |
choice | Combo box, with editable="yes" with free input, with list="yes" list box | value of the selected entry |
The entries of a choice field are given in <Option>, preferably from the data:
<Formfield type="choice" name="country" value="{@country}">
<ForAll select="country">
<Option value="{@code}"><Value select="."/></Option>
</ForAll>
</Formfield>
More properties: readonly="yes" (cannot be changed), required="yes" (required field), maxlength (maximum number of characters in text fields), checked="yes" (check box checked, radio button selected) and tooltip (short description that viewers show when the mouse is over the field and that screen readers read out).
Field names
The name is required. Dots in the name build a hierarchy: order.item.4711.quantity results in the nodes order, item and 4711 with the field quantity in the PDF. The tools for reading out the data return the fully qualified names. Like all attributes, names are built with XPath in curly braces:
<Formfield name="{concat('order.item.', @no, '.quantity')}"/>
A name may occur only once. A second field with the same name is an error, and the second field is omitted. Exceptions:
- Radio buttons with the same name form a group.
shared="yes": the field appears several times and shows the same value everywhere, for example a customer number on every page or a field in a repeated table head.
A name must not be both a field and the beginning of another name (a.b and a.b.c).
Placement and size
A field can stand in three places:
- In a paragraph, like a word in the text. The baseline of the field’s text is the baseline of the paragraph. If the field is higher than the line distance, the line becomes higher.
- In
<PlaceObject>, withwidthandheightin grid cells or as lengths. - Directly in
<Td>. A text field or choice field withoutwidthfills the width of the cell, withoutheightits height. For the column width, the field counts withminwidth(default: twice the font size); fixed widths are given in<Columns>as usual. Check boxes and radio buttons do not fill the cell, they followalignandvalignof the cell.
Without settings, a text field is ten times as wide and one and a half times as high as the font size, a multi line text field is three lines high, a list box as high as up to five entries, and a check box or radio button as large as the font size. Some viewers place the text too low when editing fields that are hardly higher than the font; one and a half times the font size is a good minimum.
Label and field in the same paragraph are on the same baseline. In separate table cells this is not exactly the case, because the field centers its text vertically with the dimensions of the font, while the paragraph uses its line distance. For clean lines, put label and field into one paragraph and align the fields with a tab stop.
Appearance
Without further settings, a field has neither a border nor a background; viewers usually highlight fields themselves. Border, background and text color come from CSS (element formfield) or from the attributes background-color, border-width, border-color, border-style and color:
<Stylesheet>
formfield { background-color: #eef3fb; border-bottom: 0.5pt solid #7a8ca8 }
td formfield { border: none }
formfield.important { border: 1pt solid red }
</Stylesheet>
The sides of the border can be set individually; solid, dashed and dotted are drawn. Radio buttons are round, check boxes get a cross, both in the text color.
Border and background of text fields and choice fields are visible on the screen only. They are left out when printing, only the text filled in is printed: on paper, the filled in form looks like a paper form someone has written on. For this, border and background are in an annotation of their own below the field. It is marked as not printable and also belongs to an optional content group that is off for printing, because not every viewer respects both. Check boxes and radio buttons keep their border in print. PDF/A and PDF/UA allow neither annotations that are not printed nor switching the group when printing; there, border and background are printed as well.
The publisher sets the appearance when the file is opened, with the font of the surrounding text (or the one given in fontfamily) and with all typesetting features. When editing, the viewer redraws the field. For this, it needs a font in the PDF that contains all characters someone might type:
- Without
fontfamily, the viewer edits with Helvetica. It is not embedded and covers only Western European characters reliably. - With
fontfamily, the publisher additionally embeds the regular font of the family completely. The file grows by the size of the font file.
How well the viewers use this font differs (see below). When a viewer redraws a field while editing, it takes over border and background only in a simple form: one border color and width for all sides, one background color. This applies to check boxes and radio buttons and to all fields in PDF/A and PDF/UA; for the other fields, border and background stay, because they are not part of the field itself.
Reading out the form data
A filled in form contains the values under the field names. Suitable tools:
pdfcpu form export form.pdf form.jsonwrites all fields as JSON, grouped by kind (textfield,checkbox,radiobuttongroup,combobox,listbox).pdftk form.pdf dump_data_fields_utf8prints name, kind and value of each field as text.qpdf --json --json-key=acroform form.pdfreturns the fields with full name and value as JSON.
The recipe Order form from the data shows how to get the order lines from the JSON with jq.
PDF/UA, PDF/A and PDF/X
- PDF/UA (accessibility): every field becomes a structure element
Formin the surrounding paragraph or table cell; the tab order follows the structure. Every field needs atooltip, otherwise there is an error. - PDF/A-3: text fields and choice fields need
fontfamily, so that the font for editing is embedded; otherwise there is an error. As in the rest of the document, the colors must match the output intent: RGB colors such as#eef3fbneed an RGB color profile. - PDF/X has no form fields. The publisher then outputs only the appearance of the fields as normal page content and warns once.
Behavior of PDF viewers
Forms are filled in with very different programs. State of the tests (December 2026):
| Viewer | Filling in and saving | Notes |
|---|---|---|
| Adobe Acrobat and Reader | reliable | uses the editing font for all characters |
| Firefox (pdf.js) | reliable | while typing, an input field of the browser appears; saving uses the editing font |
| Chrome, Edge (PDFium) | reliable | shows no tooltips; uses the editing font only for Western European characters, system fonts otherwise |
| Preview (macOS) | with restrictions | ignores the editing font; for fields that occur more than once and have a dot in their name (radio buttons, shared), the value does not end up at the field; writes formally broken files; draws text fields itself, with the text slightly lower |
| Files app (iOS) | yes | discards the editing font when saving; check boxes react to tapping only outside the form filling mode |
| Skim (macOS) | no | does not save form values; like Preview, draws text fields slightly lower |
Repair files saved by Preview with qpdf file.pdf repaired.pdf before reading them out; pdftk then reads them correctly.
Testing
<Trace dump-formfields="yes"/> writes the fields with name, kind, value, properties and size to the file <jobname>-formfields.xml. The quality assurance (sp compare) compares it with a file reference-formfields.xml in the test directory, if there is one.
What is not possible
- JavaScript in the form: calculations, validation and number formats while typing.
- Buttons to submit or reset the form.
- Signature fields and multiple selection in list boxes.
- Form fields from HTML (
<input>,<select>).
