Repository navigation
Conversation
|
✅ DCO Check Passed Thanks @wittjeff, all your commits are properly signed off. 🎉 |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Born-digital PDFs carry their interactive form layer machine-readable, but the PDF pipeline dropped it: field names, types, values, checkbox states and tooltips in widget annotations were never read (discussion docling-project#301). - docling/utils/form_utils.py: lossless widget-annotation extraction via PDFium's annotation API (FormFieldInfo: name, type, value, /TU tooltip, checked state, required/readonly flags, widget rect), plus a builder that represents fields in a DoclingDocument as one FormItem per page with a key/value GraphData (checkable fields as checkbox cells with explicit checked/unchecked text). - PdfDocumentBackend.get_form_fields() default (empty), implemented once in ManagedPdfiumDocumentBackend, so both the docling-parse and pypdfium2 backends serve it from their existing pypdfium2 document handle. - PdfPipelineOptions.extract_form_fields (default False) gates attachment in StandardPdfPipeline._assemble_document; metadata-only, no models involved. - Hand-crafted AcroForm fixture: filled required text field with /TU, checked and unchecked checkboxes, a checkbox checked only via /AS (no /V), and a Link annotation that extraction must skip. Backend/document/pipeline tests incl. after-unload, malformed-form-env, and non-PDFium-backend fallbacks. Properties without a typed schema slot yet (tooltip, field type, flags) stay on FormFieldInfo; a docling-core schema proposal follows separately. Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
08e1204 to
52fabd4
Compare
|
@wittjeff Many thanks for volunteering and taking the effort to push this further! I have read the discussion in #301 and would like to give some input on the desired approach here. 1. Please use The Concretely, replace the current from docling_core.types.doc import BoundingBox, CoordOrigin, ProvenanceItem
for page_no, page_fields in by_page.items():
fri = doc.add_field_region(
prov=ProvenanceItem(page_no=page_no, bbox=page_bbox, charspan=(0, 0)),
)
for f in page_fields:
fi = doc.add_field_item(parent=fri)
# /T is dictionary metadata, not page text — no prov
doc.add_field_key(text=f.name, parent=fi)
value_text = (
("checked" if f.checked else "unchecked")
if f.checked is not None
else f.value
)
doc.add_field_value(
text=value_text,
parent=fi,
kind="fillable",
prov=ProvenanceItem(
page_no=page_no,
bbox=BoundingBox(
l=f.rect[0], b=f.rect[1], r=f.rect[2], t=f.rect[3],
coord_origin=CoordOrigin.BOTTOMLEFT,
),
charspan=(0, len(value_text)),
),
)Tooltip ( 2. Thread the fields through layout — don't attach them past it. Right now Widgets should enter the pipeline at the layout stage, not after it. That means edits in three places:
The docling-core primitives ( 3. We'll enable the docling-parse route so pypdfium2 isn't needed here. Out of scope for this PR, only informational: |
|
@wittjeff FYI, I am doing an iteration on this. I found that it quickly gets messy in the details, so might need some time. |
|
@cau-git |
|
@wittjeff I put up a PR with an effort to use the acroform widgets, which addresses the feedback above. It also uses docling-parse natively. There is still a lot of iterations to do but I would propose we start from there. Currently, only value fields are considered, and no binding from form labels/fieldnames yet. See: #4140 |
|
@cau-git Thanks for taking this over and for #4140. Agreed that it is the right shape: widgets entering at the layout stage, I read #4140 against Well-Tagged PDF 1.0, which PDF/UA-2 is built on, and I think it is worth aligning the follow-on work with that spec now, while the contract is still fluid. Three things fall out of it:
The full proposal, with a phased plan across docling-parse, docling-core, and docling, is in #4143. Detailed review notes on #4140 itself (checkbox representation vs. the HTML backend, multi-select I am travelling most of September, so response times will be uneven, but I can keep moving the stacked pieces in the background. |
|
Closing this as superseded by #4140. @cau-git's point stands and I agreed with it at the time: Rather than redesign this draft onto the typed items in parallel, the remaining pieces are better placed where that work already lives:
Nothing here is lost — #4143 remains the proposal of record for the PDF/UA-2 alignment, and the implementation now follows #4140. Thanks for picking it up. 🤖 Generated with Claude Code |
Follow-up to the offer in #301 (discussion): this makes the PDF pipeline read the interactive form layer of born-digital PDFs instead of dropping it.
What it does
docling/utils/form_utils.py— lossless widget-annotation extraction via PDFium's annotation API. Each field yields aFormFieldInfo: fully qualified name (/T), type (text/checkbox/radio/combobox/listbox/pushbutton/signature), current value (/V), tooltip (/TU— the PDF/UA accessible name), checkbox/radio state, required/read-only flags, and the widget rectangle.PdfDocumentBackend.get_form_fields()— new backend surface with an empty default (mirroringget_document_outline()), implemented once inManagedPdfiumDocumentBackendso both the docling-parse and pypdfium2 backends serve it from the pypdfium2 document handle they already hold.PdfPipelineOptions.extract_form_fields(defaultFalse) — when enabled,StandardPdfPipelineattaches oneFormItemper page-with-fields, carrying a key/valueGraphData: the field name as akeycell (no page provenance — it's dictionary metadata, not page text), linkedto_valueto a value cell anchored at the widget rectangle. Checkable fields becomecheckboxcells with explicitchecked/uncheckedtext, so state survives every export path. Metadata-only: no models run, negligible cost; scanned/flattened forms have no widget annotations and are unaffected.What it deliberately does not do (yet)
FormFieldInfofor API users but not yet serialized into the document. We'll follow up with a docling-core schema proposal for those (flagged in Expose and add structured output for forms and key-value regions #301); this PR keeps the extraction layer and the schema discussion decoupled.VlmPipelineis untouched; the option lives onPdfPipelineOptions.Tests
tests/test_form_extraction.pywith a hand-crafted AcroForm fixture (tests/data/pdf/sources/acroform_sample.pdf: a filled required text field with/TU, a checked and an unchecked checkbox, a checkbox checked only via/ASwith no/V— the viewer-filled pattern, resolved through the appearance state — and a Link annotation that field extraction must skip, plus visible text labels): backend extraction across both PDF backends, document representation (cells/links/provenance), the pipeline option gate in both positions, the no-form fallback on an existing fixture, plus degradation paths —get_form_fields()afterunload(), a form environment that fails to initialize, and the empty default on non-PDFium backends (image input).cc @cau-git — this is the "populate the existing model from widget annotations" PR from the discussion. @Ptark, your pypdfium2 approach is exactly the route taken (shared utility on the backends' existing handle); review from you would be very welcome, and if you'd like to build any of your richer extraction (JS actions, etc.) on top, happy to co-develop.
Checklist:
🤖 Generated with Claude Code