Skip to content

Give every active form widget its own appearance, and ask the viewer to redraw only text it cannot shape (#348, #59) - #387

Merged
jakejackson1 merged 6 commits into
feature/pdfa-2-conformancefrom
fix/348-pdfa-active-forms
Sep 23, 2026
Merged

jakejackson1 merged 6 commits into
feature/pdfa-2-conformancefrom
fix/348-pdfa-active-forms

Conversation

@jakejackson1

@jakejackson1 jakejackson1 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #348
Fixes #59

Active form widgets now come with their own appearances. PDF/A documents rely on those alone. Ordinary documents ask the viewer to redraw widgets only when a field's text needs shaping that mPDF cannot do yet.

What changed

Appearances for every active form. Every text field, textarea, password, list box, combo box and push button now gets an /AP stream, in every document. The layout is worked out when the widget is placed, because the field's font can only be measured then.

  • It draws the value, * for a password, a word-wrapped textarea, and the selected option. A list box highlights the selection and scrolls to it.
  • It also draws a button's caption or icon, over the field's background and border.
  • Core-font text is written as Windows-1252 and embedded-font text as UTF-16.
  • Push buttons use /N << /Push … >> /AS /Push, which PDF/A requires of a Btn widget. Outside PDF/A they keep their actions alongside it.
  • Hidden inputs and noprint buttons get appearances too. Their /F 2 and /F 0 flags are unchanged outside PDF/A.
  • Viewers that ignore /NeedAppearances (many mobile, print and preview ones) previously drew these fields empty.

Checkboxes and radio buttons are vector shapes everywhere. Every document now uses the shapes that PDF/A and PDF/X already drew, as proper form XObjects with a /BBox and both an on and an off stream. The ZapfDingbats appearances they replace had no bounding box, used the bare name /Off for an unchecked box, and a glyph for an unselected radio. They were only usable because the viewer was always asked to redraw them. The ZapfDingbats path could not be embedded under PDF/A or PDF/X, and that is what made checkboxes throw (#348). Form::$formUseZapD is removed. It was a public property, reachable as $mpdf->form->formUseZapD but not a config key, and it no longer selects anything.

/NeedAppearances only for text the appearances can't shape. mPDF's appearance text is neither shaped nor reordered (#408). So /NeedAppearances true is written only when a field's value, options or caption:

  • is right-to-left (the existing $mpdf->pregRTLchars test), or
  • is in a script with a shaper of its own (Arabic, Syriac, NKo, Mandaic, Indic, Thai, Lao, Khmer, Sinhala, Myanmar and the South East Asian scripts). The new Otl::hasComplexScript() checks this by reusing ScriptRuns::split() and Otl::selectShaper(), the same pair OTL uses to choose a shaper.

A Latin, Greek or Cyrillic form no longer carries the flag. Once #408 shapes the appearances, the flag can go; the code comment points there. Under PDF/A the flag is never written, so a PDF/A field in such a script shows its unshaped appearance until #408 is done.

#59. /DR names /ZaDb << /Type /Font /Subtype /Type1 /BaseFont /ZapfDingbats >> only when the flag is written and the form has a checkbox or radio button. That is the font viewers redraw them in. PDF/A never asks for a redraw, and PDF/X cannot name an unembedded font, so neither gets it. Without the flag, poppler draws the widgets from their appearances and has nothing to warn about. With it, the font is there to find.

What PDF/A forbids, only under PDF/A:

  • JavaScript, submit and reset actions are left out, and so is /CO, which follows from dropping the JavaScript.
  • Hidden inputs and noprint buttons are written with the print flag.
  • Colours in the appearances follow the output intent (RGB or CMYK).
  • Without PDFAauto, the dropped actions and noprint are recorded as PDF/A warnings, so Output() throws. Mpdf::pdfaxWarning() is now public so that Form can share that gate.

A checkbox or radio button now names its own field font in /DA, rather than whichever font was current at output time.

Snapshots

Each is refreshed in its own commit, after checking the rasterised pages:

  • page-break-avoid-forms
    • The select shows its selected option ("Second option, selected") rather than its export value "2".
    • The buttons show "Submit"/"Reset" instead of being blank.
    • The checkboxes and radio buttons are the vector box, tick, ring and dot.
    • The text fields look the same.
    • /NeedAppearances and /ZaDb are gone.
    • Ghostscript's "AcroForm field 'Btn' with no AP" warnings and poppler's "Unknown font tag 'ZaDb'" warnings are both gone.
  • page-break-avoid-references: only its text field is drawn differently, from its own appearance instead of Ghostscript's (RMSE about 0.012).

New fixtures, all rendering the same page of fields (tests/Snapshots/FormFields.php):

  • form-fields-static: useActiveForms off, so each field is drawn into the page.
  • form-fields-active: useActiveForms on, so every field is a widget with its own appearance. The Arabic value makes this the fixture that carries /NeedAppearances true and /ZaDb.
  • form-fields-pdfa: active forms under PDF/A-2b with PDFAauto, drawn from appearances alone, without the button actions and without /NeedAppearances.

The page has:

  • text inputs with and without a value, a password, and read-only, disabled, required and maxlength inputs;
  • a short text area and one that wraps over several lines;
  • a select with no size, a size="3" list box and a multiple select with two selections;
  • checked and unchecked checkboxes and a three-button radio group;
  • submit, reset, script and image buttons, and a hidden input;
  • a field with its colours, border and font size set in CSS;
  • an Arabic value.

All three come out byte-identical run to run. They contain no carriage returns, no local or temp paths, and only DejaVu fonts from font-bundle-lite. The image button's JPEG is embedded as is, not through GD. These fixtures will change when #330 picks up #419 (combo-box flag), #429 (disabled grey), #425 and #426.

Verification

  • veraPDF (--group=conformance): testActiveFormConforms passes 1-B, 2-B, 2-U, 3-B and 3-U, each with an sRGB and a CMYK output intent. It includes text, password, hidden, textarea, checkbox, radio, combo, list, submit, reset and a JS noprint button. The whole group passes (26 tests).
  • FormAppearanceTest:
    • Ordinary documents give every widget /AP and keep their actions and flags, in core-font and embedded-font mode.
    • Latin text writes no /NeedAppearances.
    • An Arabic value with a checkbox, or a Hebrew option with a radio, writes /NeedAppearances and /ZaDb. A Thai caption writes the flag only.
    • pdftotext prints nothing, with or without the flag.
    • PDF/A widgets have /AP and /F 4, with no /AA and no /NeedAppearances.
    • PDF/A without PDFAauto warns about actions and noprint.
    • PDF/X checkboxes carry no ZapfDingbats.
  • OtlTest: hasComplexScript() for Latin, Greek and Cyrillic (false), and Devanagari, Arabic, Thai and mixed text (true). The form tests use Arabic, Hebrew and Thai because the bundled Devanagari font (FreeSerif) has SMP glyphs, which active forms refuse.
  • AnnotationObjectNumbersTest: new cases for an ordinary embedded-font form and a PDF/A form check that every /AP reference points at its appearance stream.
  • Rendering: checked and unchecked checkboxes and radios, and every other widget type, were rendered with pdftoppm and Ghostscript. Values, masks, wrapped text, selections, captions, ticks and dots all show.
  • Gates: composer test passes (3410 tests, the same 5 skips as the base branch). --group=snapshot passes (88). composer cs is clean. PHPStan 2 is clean; the $radio_color and $radio_background_color baseline counts drop to 1. php -l under PHP 5.6 is clean.
  • Rebased onto feature/pdfa-2-conformance after Paint SVG gradient stops opaque under PDF/A-1b, and write only the visibility groups the catalog lists (#346, #351) #386.

Limits

  • Appearance text is not shaped or mirrored (PDF/A widget appearance streams draw text without shaping or bidi #408). An auto font size fits the height for single-line fields and is 12pt otherwise.
  • Found along the way, not changed here: Tag\Select sets size only when it is above 1, so an HTML <select> never gets the combo-box flag and is always written as a list box.

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added bug Something isn't working enhancement New feature or request create-upstream-pr labels Sep 23, 2026
@jakejackson1

Copy link
Copy Markdown
Member Author

Support this when not PDF/A too.

jakejackson1 and others added 4 commits September 23, 2026 14:56
…he viewer to (#348)

Checkboxes and radio buttons switched to ZapfDingbats, which mPDF cannot
embed, so PDF/A and PDF/X threw. They now draw the shapes mPDF already has
for formUseZapD = false, in the colour space the output intent allows.

Under PDF/A, text fields, choices and push buttons get an appearance
stream laid out when the widget is placed (value, password mask, wrapped
textarea, selected option, list box highlight, caption or icon), the
AcroForm drops /NeedAppearances, hidden inputs and noprint buttons are
printed, and JavaScript, submit and reset actions are left out. Without
PDFAauto the dropped actions and noprint are reported as PDF/A warnings.

Other documents still ask the viewer to redraw widgets, and now name the
ZaDb font it redraws checkboxes with in /DR, which stops poppler warning
of an unknown font tag (#59).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Viewers that ignore /NeedAppearances, as many mobile, print and preview
ones do, drew these widgets empty. The appearances PDF/A needed are now
written for every document, with core-font text in Windows-1252 and
embedded-font text in UTF-16. Outside PDF/A the form still asks the viewer
to redraw them, and keeps its actions and its hidden and noprint flags.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…cannot shape

Every widget now carries an appearance, so /NeedAppearances is written only
when a field's value, options or caption is in a right-to-left script or a
script with a shaper of its own (Otl::hasComplexScript), which mPDF's
appearances neither reorder nor shape (#408). PDF/A never writes it. /ZaDb
joins /DR only alongside the flag, when there is a checkbox or radio button
to redraw (#59).

Without the flag, viewers draw checkboxes and radio buttons from their own
appearances, and the ZapfDingbats ones have no bounding box and no off state
to draw. Every document now uses the vector shapes PDF/A and PDF/X already
drew, and the formUseZapD property that chose between them is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Ghostscript draws a widget from its appearance where it has one. In
page-break-avoid-forms the select shows its selected option rather than its
export value, the buttons show their captions, and the checkboxes and radio
buttons are the vector shapes; in page-break-avoid-references only the text
field is drawn differently. Neither document asks the viewer to redraw its
widgets any more, so /NeedAppearances and /ZaDb are gone from both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1 jakejackson1 changed the title Draw every active form widget in a PDF/A document instead of asking the viewer to (#348) Give every active form widget its own appearance, and ask the viewer to redraw only text it cannot shape (#348, #59) Sep 23, 2026
@jakejackson1
jakejackson1 force-pushed the fix/348-pdfa-active-forms branch from 55735e8 to 055a94e Compare September 23, 2026 05:08
jakejackson1 and others added 2 commits September 23, 2026 19:52
…heckout writes no CR

The paths were string literals running over two lines. With text=auto, Git checks them
out with CRLF on Windows, and the carriage return reached the appearance stream, so the
page-break-avoid-forms snapshot differed there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… PDF/A

The same page of fields renders three ways: into the page without active
forms (form-fields-static), as widgets with their own appearances
(form-fields-active) and as a PDF/A-2b document drawn from the appearances
alone (form-fields-pdfa). The page has text, password, read-only, disabled,
required and maxlength inputs, short and wrapped text areas, a combo box, a
list box and a multiple select, checkboxes and a radio group, submit, reset,
script and image buttons, a hidden input, a field styled in CSS, and an
Arabic value, which has the active document ask the viewer to redraw its
widgets.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 merged commit 1bb1b2c into feature/pdfa-2-conformance Sep 23, 2026
29 checks passed
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
…to redraw only text it cannot shape (#348, #59) (#387)

* Draw every active form widget in a PDF/A document instead of asking the viewer to (#348)

Checkboxes and radio buttons switched to ZapfDingbats, which mPDF cannot
embed, so PDF/A and PDF/X threw. They now draw the shapes mPDF already has
for formUseZapD = false, in the colour space the output intent allows.

Under PDF/A, text fields, choices and push buttons get an appearance
stream laid out when the widget is placed (value, password mask, wrapped
textarea, selected option, list box highlight, caption or icon), the
AcroForm drops /NeedAppearances, hidden inputs and noprint buttons are
printed, and JavaScript, submit and reset actions are left out. Without
PDFAauto the dropped actions and noprint are reported as PDF/A warnings.

Other documents still ask the viewer to redraw widgets, and now name the
ZaDb font it redraws checkboxes with in /DR, which stops poppler warning
of an unknown font tag (#59).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Give every active text field, choice and push button its own appearance

Viewers that ignore /NeedAppearances, as many mobile, print and preview
ones do, drew these widgets empty. The appearances PDF/A needed are now
written for every document, with core-font text in Windows-1252 and
embedded-font text in UTF-16. Outside PDF/A the form still asks the viewer
to redraw them, and keeps its actions and its hidden and noprint flags.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Ask the viewer to redraw form fields only for text their appearances cannot shape

Every widget now carries an appearance, so /NeedAppearances is written only
when a field's value, options or caption is in a right-to-left script or a
script with a shaper of its own (Otl::hasComplexScript), which mPDF's
appearances neither reorder nor shape (#408). PDF/A never writes it. /ZaDb
joins /DR only alongside the flag, when there is a checkbox or radio button
to redraw (#59).

Without the flag, viewers draw checkboxes and radio buttons from their own
appearances, and the ZapfDingbats ones have no bounding box and no off state
to draw. Every document now uses the vector shapes PDF/A and PDF/X already
drew, and the formUseZapD property that chose between them is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Refresh the form snapshots for the appearances every widget now carries

Ghostscript draws a widget from its appearance where it has one. In
page-break-avoid-forms the select shows its selected option rather than its
export value, the buttons show their captions, and the checkboxes and radio
buttons are the vector shapes; in page-break-avoid-references only the text
field is drawn differently. Neither document asks the viewer to redraw its
widgets any more, so /NeedAppearances and /ZaDb are gone from both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Keep the check box and radio paths on one source line, so a Windows checkout writes no CR

The paths were string literals running over two lines. With text=auto, Git checks them
out with CRLF on Windows, and the carriage return reached the appearance stream, so the
page-break-avoid-forms snapshot differed there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Snapshot every form field, drawn statically, as active widgets and in PDF/A

The same page of fields renders three ways: into the page without active
forms (form-fields-static), as widgets with their own appearances
(form-fields-active) and as a PDF/A-2b document drawn from the appearances
alone (form-fields-pdfa). The page has text, password, read-only, disabled,
required and maxlength inputs, short and wrapped text areas, a combo box, a
list box and a multiple select, checkboxes and a radio group, submit, reset,
script and image buttons, a hidden input, a field styled in CSS, and an
Arabic value, which has the active document ask the viewer to redraw its
widgets.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
…to redraw only text it cannot shape (#348, #59) (#387)

* Draw every active form widget in a PDF/A document instead of asking the viewer to (#348)

Checkboxes and radio buttons switched to ZapfDingbats, which mPDF cannot
embed, so PDF/A and PDF/X threw. They now draw the shapes mPDF already has
for formUseZapD = false, in the colour space the output intent allows.

Under PDF/A, text fields, choices and push buttons get an appearance
stream laid out when the widget is placed (value, password mask, wrapped
textarea, selected option, list box highlight, caption or icon), the
AcroForm drops /NeedAppearances, hidden inputs and noprint buttons are
printed, and JavaScript, submit and reset actions are left out. Without
PDFAauto the dropped actions and noprint are reported as PDF/A warnings.

Other documents still ask the viewer to redraw widgets, and now name the
ZaDb font it redraws checkboxes with in /DR, which stops poppler warning
of an unknown font tag (#59).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Give every active text field, choice and push button its own appearance

Viewers that ignore /NeedAppearances, as many mobile, print and preview
ones do, drew these widgets empty. The appearances PDF/A needed are now
written for every document, with core-font text in Windows-1252 and
embedded-font text in UTF-16. Outside PDF/A the form still asks the viewer
to redraw them, and keeps its actions and its hidden and noprint flags.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Ask the viewer to redraw form fields only for text their appearances cannot shape

Every widget now carries an appearance, so /NeedAppearances is written only
when a field's value, options or caption is in a right-to-left script or a
script with a shaper of its own (Otl::hasComplexScript), which mPDF's
appearances neither reorder nor shape (#408). PDF/A never writes it. /ZaDb
joins /DR only alongside the flag, when there is a checkbox or radio button
to redraw (#59).

Without the flag, viewers draw checkboxes and radio buttons from their own
appearances, and the ZapfDingbats ones have no bounding box and no off state
to draw. Every document now uses the vector shapes PDF/A and PDF/X already
drew, and the formUseZapD property that chose between them is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Refresh the form snapshots for the appearances every widget now carries

Ghostscript draws a widget from its appearance where it has one. In
page-break-avoid-forms the select shows its selected option rather than its
export value, the buttons show their captions, and the checkboxes and radio
buttons are the vector shapes; in page-break-avoid-references only the text
field is drawn differently. Neither document asks the viewer to redraw its
widgets any more, so /NeedAppearances and /ZaDb are gone from both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Keep the check box and radio paths on one source line, so a Windows checkout writes no CR

The paths were string literals running over two lines. With text=auto, Git checks them
out with CRLF on Windows, and the carriage return reached the appearance stream, so the
page-break-avoid-forms snapshot differed there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Snapshot every form field, drawn statically, as active widgets and in PDF/A

The same page of fields renders three ways: into the page without active
forms (form-fields-static), as widgets with their own appearances
(form-fields-active) and as a PDF/A-2b document drawn from the appearances
alone (form-fields-pdfa). The page has text, password, read-only, disabled,
required and maxlength inputs, short and wrapped text areas, a combo box, a
list box and a multiple select, checkboxes and a radio group, submit, reset,
script and image buttons, a hidden input, a field styled in CSS, and an
Arabic value, which has the active document ask the viewer to redraw its
widgets.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant