Skip to content

feat(pdf): key form fields by their /TU description and skip artifact widgets - #4144

Merged
PeterStaar-IBM merged 2 commits into
docling-project:feat/acroform-native-fieldsfrom
wittjeff:feat/acroform-ua2-labels
Nov 12, 2026
Merged

PeterStaar-IBM merged 2 commits into
docling-project:feat/acroform-native-fieldsfrom
wittjeff:feat/acroform-ua2-labels

Conversation

@wittjeff

@wittjeff wittjeff commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4140 (base branch feat/acroform-native-fields, rebased onto 505a96b). Phase 2 of the follow-on proposal in #4143: the smallest docling-only step that aligns the form stage with Well-Tagged PDF 1.0 (the basis of PDF/UA-2) without touching the docling-core schema.

Since the first version of this PR, #4140 itself absorbed the zero-size and push-button skips, so those are gone from here. Two commits remain:

1. fix(acroform): never key a checkbox widget by its own layout cluster (cherry-pickable into #4140)

CHECKBOX_SELECTED / CHECKBOX_UNSELECTED are in TEXT_ELEM_LABELS, so _match_text_container could pick the checkbox cluster the widget sits in as its "paragraph" key container. The option label then appeared twice (as the key and on the nested checkbox child) and the region's source_container_id pointed at a cluster that promotion had already dropped, so assembly emitted a stray field_region. Checkbox clusters are now excluded from key-container candidates; the label rides on the checkbox child only. The existing checkbox test is tightened to assert a keyless fallback region.

2. feat(pdf): key standalone form fields by their /TU description

WTPDF 8.10.2.1 lists the sources of context for a widget (structure-tree Lbl, the field's TU, the widget's Contents) and states that the field name (T) does not contribute. So:

  • A widget inlined in a text paragraph keeps feat: integrate native AcroForm widgets as typed fields #4140's paragraph key (key_source="layout", with provenance).
  • Any other widget (FORM-matched or fallback) gets a FieldKeyItem from its /TU when present (key_source="tooltip", no provenance, since it is dictionary metadata rather than page text). Nothing is inferred from geometry or from /T.
  • FieldItemPrediction.key_source records where the key came from so structure-tree labels and /Contents can be added later without changing the contract.

What does not change

Layout prediction handling, region binding, fallback regions, duplicate suppression, reading-order placement, and the extract_form_fields=False no-op are untouched. Document schema unchanged; FieldKeyItem already exists in docling-core.

Tests

tests/test_form_extraction.py: the unit test gives one widget a /TU and asserts the key, its source, and the absence of a bbox through mapping, assembly, and materialization. The pipeline test now asserts two keys on acroform_sample.pdf: the paragraph key (with provenance) for the three inlined checkboxes, and Full legal name (no provenance) for the text field in the page-wide region. The first checkbox also carries a /TU but is inlined, so the paragraph wins and no second key appears.

Docs

Option description, docs/usage/advanced_options.md, and the packaged usage skill reference no longer describe fields as keyless; they now state the paragraph-then-/TU rule, the nested checkbox child, and the skipped widgets.

Base note (2026-10-06)

The same two commits rebased onto wittjeff/docling:rebase/acroform-native-fields (the fast-forwardable continuation of feat/acroform-native-fields offered on #4140) are kept at wittjeff/docling:feat/acroform-ua2-labels-main. There tests/test_form_extraction.py is 6/6 and make validate is clean against current main. This PR branch stays on the current base so its diff remains the two commits; it will be swapped for the rebased branch once #4140 moves.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @wittjeff, all your commits are properly signed off. 🎉

wittjeff and others added 2 commits September 3, 2026 11:39
CHECKBOX_* clusters are in TEXT_ELEM_LABELS, so a /Btn widget sitting
inside its detected checkbox cluster matched that cluster as its
paragraph key container. The option label then appeared twice (as the
key and on the nested checkbox child) and the region pointed at a
cluster that promotion had already dropped, so assembly emitted it as a
stray field_region. Exclude checkbox clusters from key-container
candidates; the label rides on the checkbox child only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
Stacked on docling-project#4140. Well-Tagged PDF 1.0, the basis of PDF/UA-2, lists a
field's /TU entry among the sources of context for a widget (8.10.2.1)
and states that the field name (/T) does not contribute. A widget that
is not inlined in a paragraph (a FORM-matched or fallback field) now
gets a FieldKeyItem with its /TU text, without provenance since it is
dictionary metadata rather than page text. Widgets inlined in a
paragraph keep the paragraph as their key.

FieldItemPrediction records where the key came from (layout or
tooltip) so structure-tree labels can be added later without changing
the contract. Docs and option text updated: fields are no longer
described as keyless.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
@wittjeff
wittjeff force-pushed the feat/acroform-ua2-labels branch from 8691352 to 4c198e5 Compare September 3, 2026 15:46
@wittjeff
wittjeff force-pushed the feat/acroform-ua2-labels branch 2 times, most recently from cc3bcc4 to 4c198e5 Compare October 6, 2026 14:20
@PeterStaar-IBM
PeterStaar-IBM merged commit f9b3d47 into docling-project:feat/acroform-native-fields Nov 12, 2026
6 checks passed
@wittjeff
wittjeff deleted the feat/acroform-ua2-labels branch November 12, 2026 11:18
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.

2 participants