Skip to content

feat: add a hidden option for a form field's visibility - #1791

Merged
blikblum merged 1 commit into
foliojs:masterfrom
KaiPressmar:acroform-annotation-flag-option
Sep 5, 2026
Merged

feat: add a hidden option for a form field's visibility#1791
blikblum merged 1 commit into
foliojs:masterfrom
KaiPressmar:acroform-annotation-flag-option

Conversation

@KaiPressmar

@KaiPressmar KaiPressmar commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature. Fixes #1793.

A small, purpose-built option, along the lines invited in docs/forms.md's Advanced Form Field Use section ("If an option is not supported, open an issue on Github and it will be considered for addition to the API").

Context

There's no supported way to build a field that starts hidden — e.g. one an interactive action (see #1790) reveals later. The Widget annotation's own visibility/print flags (F, distinct from the field's own Ff flags) are always defaulted to 4 (print only) by formAnnotation(), with no override, and no option maps to F at all.

The change

Adds a hidden option, accepted by all form annotation methods, mapped by a new mapVisibility(options, pdfObject) step (mirroring the other unconditional mappers): hidden: true sets F to 6 (Hidden + Print — not shown or interactive until revealed, but still printable once it is), instead of the usual default of 4.

doc.formPushButton('btn1', 10, 200, 100, 30, { hidden: true });

Demo

Attached: a minimal PDF pair (two push buttons, one built with hidden: true, before/after this change) plus screenshots from Adobe Acrobat/Reader. Before: both buttons show. After: the one built with hidden: true is actually hidden.

image

Testing

  • yarn test:unit — all existing tests pass unchanged, plus two new ones: a field built with hidden: true, and confirming the usual default still applies when it isn't given.
  • yarn lint / yarn format — clean.

Checklist:

  • Unit Tests
  • Documentation
  • Update CHANGELOG.md
  • Ready to be merged

cc @blikblum for review.

@KaiPressmar KaiPressmar changed the title fix: recognize a form field's raw F (annotation flags) option fix: form fields silently drop a custom F (visibility) option Sep 5, 2026
pdfkit deliberately restricted AcroForm options to documented mappings
and a small set of raw escape hatches, with a stated intent to shrink
and eventually remove even those. Building a field that starts hidden
(e.g. for an interactive action to reveal later) had no supported way
to reach the API at all: the Widget annotation's own visibility flags
(F, distinct from the field's own Ff flags) are always defaulted to 4
(print only) with no override.

Add a dedicated hidden option instead, consistent with the project's
stated direction of adding purpose-built options rather than widening
raw dictionary access: it needs no PDF dictionary or flag-value
knowledge, and reads as what it does.
@KaiPressmar
KaiPressmar force-pushed the acroform-annotation-flag-option branch from b5177c7 to 4c1883a Compare September 5, 2026 12:13
@KaiPressmar KaiPressmar changed the title fix: form fields silently drop a custom F (visibility) option feat: add a hidden option for a form field's visibility Sep 5, 2026
@KaiPressmar

Copy link
Copy Markdown
Contributor Author

Updated: same reasoning as #1790 — replaced the raw F escape hatch with a purpose-built hidden option instead. Description and diff updated above.

@KaiPressmar

Copy link
Copy Markdown
Contributor Author

Note: the f-before.pdf/f-after.pdf attached above were built against an earlier version of this PR (a raw F option, before the switch to the hidden option). They still demonstrate the same before/after behavior visually, but I'll swap in ones built against the current hidden-based code shortly.

@blikblum
blikblum merged commit 7c36fbe into foliojs:master Sep 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support building a form field that starts hidden (hidden option)

2 participants