Skip to content

Commit ffc17b6

Browse files
committed
Restrict AcroForm options to documented mappings and explicit escape hatches.
1 parent 2fdafa2 commit ffc17b6

4 files changed

Lines changed: 293 additions & 219 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Unreleased
44

5+
- [BREAKING CHANGE] Restrict AcroForm options to documented mappings and explicit escape hatches.
6+
57
### [v0.19.1] - 2026-06-10
68

79
- Fix RGB JPEG embedded as DeviceGray (0.19.0 regression) (#1734)

docs/forms.md

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ doc.initForm();
1616
Form annotations are added using the following document methods.
1717

1818
- `formText( name, x, y, width, height, options)`
19-
- `formPushButton( name, x, y, width, height, name, options)`
19+
- `formPushButton( name, x, y, width, height, options)`
2020
- `formCombo( name, x, y, width, height, options)`
2121
- `formList( name, x, y, width, height, options)`
22+
- `formRadioButton( name, x, y, width, height, options)`
23+
- `formCheckbox( name, x, y, width, height, options)`
2224

2325
The above methods call the `formAnnotation` method with
24-
type set to one of `text`, `pushButton`, `radioButton`, `combo` or `list`.
26+
type set to one of `text`, `pushButton`, `radioButton`, `checkbox`, `combo`
27+
or `list`.
2528

2629
- `formAnnotation( name, type, x, y, width, height, options)`
2730

@@ -35,10 +38,11 @@ information on `name` in the **Field Names** section below.
3538

3639
### `options` Parameter
3740

38-
#### Common Options
41+
#### Common Annotation Options
3942

40-
Form Annotation `options` that are common across all form annotation types are:
43+
The following `options` are accepted by all form annotation methods:
4144

45+
- `parent` [_PDFReference_] - Parent field returned by `formField`.
4246
- `required` [_boolean_] - The field must have a value by the time the form is submitted.
4347
- `noExport` [_boolean_] - The field will not be exported if a form is submitted.
4448
- `readOnly` [_boolean_] - The user may not change the value of the field, and
@@ -47,22 +51,24 @@ Form Annotation `options` that are common across all form annotation types are:
4751
- `value` [_number|string_] - The field's value.
4852
- `defaultValue` [_number|string_] - The default value to which the field
4953
reverts if a reset-form action is executed.
54+
- `backgroundColor` - Field background color.
55+
- `borderColor` - Field border color.
56+
- `fontSize` [_number_] - Sets the font size used in the field appearance string.
57+
The default, `0`, means auto sizing.
5058

51-
Some form annotations have `color` options. You can use an array of RGB values,
52-
a hex color, or a named CSS color value for that option.
53-
54-
- `backgroundColor` - field background color
55-
- `borderColor` - field border color
59+
Color options accept an array of RGB values, a hex color, or a named CSS color.
60+
Method-specific options listed below are accepted in addition to these common
61+
options.
5662

5763
#### Text Field Options
5864

59-
- `align` [_string_] - Sets the alignment to `left`,
60-
`center` or `right`.
65+
These options are accepted by `formText`:
66+
67+
- `align` [_string_] - Sets the alignment to `left`, `center` or `right`.
6168
- `multiline` [_boolean_] - Allows the field to have multiple lines of text.
6269
- `password` [_boolean_] - The text will be masked (_e.g._ with asterisks).
63-
- `noSpell` [_boolean_] - If set, text entered in the field is not spell-checked
70+
- `noSpell` [_boolean_] - If set, text entered in the field is not spell-checked.
6471
- `format` [_object_] - See the section on **Text Field Formatting** below.
65-
- `fontSize` [_number_] - Sets the fontSize (default or 0 means auto sizing)
6672

6773
```js
6874
doc.formText('leaf2', 10, 60, 200, 40, {
@@ -75,13 +81,17 @@ doc.formText('leaf2', 10, 60, 200, 40, {
7581
});
7682
```
7783

78-
#### Combo and List Field Options
84+
#### Combo Field Options
85+
86+
These options are accepted by `formCombo`:
7987

88+
- `select` [_array_] - Array of choices to display in the combo field.
89+
- `align` [_string_] - Sets the alignment to `left`, `center` or `right`.
90+
- `edit` [_boolean_] - Allows the user to enter a value in the field.
8091
- `sort` [_boolean_] - The field options will be sorted alphabetically.
81-
- `edit` [_boolean_] - (combo only) Allow the user to enter a value in the field.
82-
- `multiSelect` [_boolean_] - Allow more than one choice to be selected.
83-
- `noSpell` [_boolean_] - (combo only) If set and `edit` is true, text entered in the field is not spell-checked.
84-
- `select` [_array_] - Array of choices to display in the combo or list form field.
92+
- `multiSelect` [_boolean_] - Allows more than one choice to be selected.
93+
- `noSpell` [_boolean_] - If set and `edit` is true, text entered in the field
94+
is not spell-checked.
8595

8696
```js
8797
opts = {
@@ -93,7 +103,18 @@ opts = {
93103
doc.formCombo('ch1', 10, y, 100, 20, opts);
94104
```
95105

96-
#### Button Field Options
106+
#### List Field Options
107+
108+
These options are accepted by `formList`:
109+
110+
- `select` [_array_] - Array of choices to display in the list field.
111+
- `align` [_string_] - Sets the alignment to `left`, `center` or `right`.
112+
- `sort` [_boolean_] - The field options will be sorted alphabetically.
113+
- `multiSelect` [_boolean_] - Allows more than one choice to be selected.
114+
115+
#### Push Button Field Options
116+
117+
These options are accepted by `formPushButton`:
97118

98119
- `label` [_string_] - Sets the label text. You can also set an icon, but for
99120
this you will need to 'expert-up' and dig deeper into the PDF Reference manual.
@@ -106,6 +127,33 @@ var opts = {
106127
doc.formPushButton('btn1', 10, 200, 100, 30, opts);
107128
```
108129

130+
#### Radio Button Field Options
131+
132+
These options are accepted by `formRadioButton`:
133+
134+
- `toggleToOffButton` [_boolean_] - Allows a selected radio button to be toggled
135+
off by clicking it again.
136+
137+
#### Checkbox Field Options
138+
139+
`formCheckbox` accepts the common annotation options.
140+
141+
### Form Field Options
142+
143+
`formField( name, options )` creates an invisible field node and accepts these
144+
options:
145+
146+
- `parent` [_PDFReference_] - Parent field returned by `formField`.
147+
- `required` [_boolean_] - The field must have a value by the time the form is submitted.
148+
- `noExport` [_boolean_] - The field will not be exported if a form is submitted.
149+
- `readOnly` [_boolean_] - The user may not change the value of the field.
150+
- `value` [_number|string_] - The field's value.
151+
- `defaultValue` [_number|string_] - The default value to which the field
152+
reverts if a reset-form action is executed.
153+
- `backgroundColor` - Field background color.
154+
- `borderColor` - Field border color.
155+
- `fontSize` [_number_] - Sets the font size used in the field appearance string.
156+
109157
### Text Field Formatting
110158

111159
When needing to format the text value of a Form Annotation, the following
@@ -254,11 +302,9 @@ The output of this example looks like this.
254302

255303
### Advanced Form Field Use
256304

257-
Forms can be quite complicated and your needs will likely grow to sometimes need
258-
to directly specify the attributes that will go into the Form Annotation or
259-
Field dictionaries. Consult the **PDF Reference** and set these attributes in
260-
the `options` object. Any options that are not listed above will be added
261-
directly to the corresponding PDF Object.
305+
Older implementations used to pass all unknown options to the internal PDF object structure. A small set of direct PDF dictionary escape hatches is still recognized: `Ff`, `MK.CA`, and `AA` when a `format` option is used but its use is discouraged and likely will be removed in future versions.
306+
307+
If an option is not supported, open an issue on Github and it will be considered for addition to the API.
262308

263309
## Font
264310

0 commit comments

Comments
 (0)