PDF pipeline drops text regions after classifying them as pictures
Problem
The standard PDF pipeline can omit most or all of the body text from some text-native safety notices published by the NSW Clinical Excellence Commission. The PDF text layer is intact, but the Markdown output replaces the affected regions with <!-- image --> placeholders.
Affected public documents are identified on the Clinical Excellence Commission safety notices site by these notice numbers:
2009-SA-001, "PEEP Valve, Expiration Diverter Assembly"2023-SN-044, "Safe use of magnesium sulfate heptahydrate in maternity services"
Public site: https://www.cec.health.nsw.gov.au/
The same symptom was also observed for 2007-SN-008 and 2021-SI-007.
Reproducer
- Download either notice from the public Clinical Excellence Commission site.
- Run
pdftotext -layout NOTICE.pdf -and confirm that headings such asBackground,Actions, orRequired actionsand their paragraphs are present. - Convert the same file with the standard Docling PDF pipeline and export Markdown.
- Compare the outputs.
For 2009-SA-001, pdftotext extracts the full Background and Actions sections. Docling emits only 39 words, the date, distribution heading, notice heading, title, and three image placeholders. For 2023-SN-044, pdftotext extracts 1,064 words while Docling emits 396 words and multiple image placeholders in place of the first-page body.
Root cause evidence
This is not missing PDF text or text encoded only in a form XObject:
- Poppler extracts the omitted text directly from the PDF text layer.
pdffontsreports embedded Arial and Symbol text fonts with Unicode mappings for the 2023 notice.pdfimages -listreports only three small embedded images in the 2009 notice and two repeated small images per page in the 2023 notice. These do not account for the large body regions replaced by image placeholders.- The exported placeholders line up with the omitted text regions.
The evidence points to the layout stage classifying text-bearing page regions as PICTURE, after which document assembly suppresses the text cells covered by those regions and exports picture placeholders. The notices use a fixed two-column template, ruled boxes, sidebars, and an obsolete watermark, which appears to trigger the misclassification. A live model trace on current main could not be completed in this investigation because the available development environments lacked required PDF or vision dependencies, so the exact layout-model label and suppression function still need confirmation.
Proposed fix
Add a conservative post-processing guard before text cells covered by a picture prediction are discarded. If a predicted picture region contains substantial native PDF text, retain those cells unless there is stronger evidence that the text is only a caption or overlaid OCR. This should preserve true text panels without turning text inside real figures into duplicate paragraphs.
An alternative is to split or relabel a predicted picture region when native text cells occupy most of its area. The decision should use existing cell geometry and confidence signals rather than document-specific template rules.
Tests
Add a synthetic, text-native PDF with:
- a two-column layout,
- bordered and shaded text panels,
- a sidebar,
- a diagonal watermark,
- small real images outside the body panels.
Assert that the standard pipeline retains the Background, Issue, and Action paragraphs while still emitting the real images as pictures. Also assert that no body paragraph is duplicated. Keep the fixture generated by the test or checked in as a synthetic PDF.
Investigation checks
- Searched open issues in
docling-project/doclingfor the notice identifiers and combinations of PDF missing text, layout, picture classification, and form XObject: no matching issue found. - Searched open pull requests with the same terms: no matching pull request found.
- Compared Poppler text extraction, font inventory, embedded-image inventory, and existing standard-pipeline Markdown for two affected files.
I ran a live trace on current main (2.133.0, default layout_heron model) against the four notices (mirrored at https://www.health.nsw.gov.au/sabs/Documents/<id>.pdf, which is not Cloudflare-gated). The hypothesis in the report is right, and the exact location is now confirmed.
Root cause
The raw Heron prediction (with settings.debug.visualize_raw_layout) contains a single low-confidence picture box covering the whole bordered body column. It survives LayoutPostprocessor._process_special_clusters because the only size guard there drops pictures covering more than 90 % of the page. Every regular text cluster inside it then becomes a picture child via the intersection_over_self > 0.8 nesting rule, and postprocess() removes those children from the regular clusters.
The text is not lost in the DoclingDocument: the reading-order stage adds the children under the PictureItem. It disappears only at Markdown export, because the Markdown serializer does not traverse picture children by default.
| Notice | picture conf | page fraction | text children nested | MD words (main) | pdftotext words |
|---|---|---|---|---|---|
| 2009-SA-001 | 0.59 | 0.70 | 48 | 36 | 385 |
| 2023-SN-044 | 0.61 | 0.77 | 33 | 396 | 1062 |
| 2007-SN-008 | 0.56 | 0.75 | 41 | 208 | 675 |
| 2021-SI-007 | — | — | 0 | 627 | 698 |
2021-SI-007 does not exhibit this failure on main; its smaller gap is unrelated to picture classification.
Workarounds available today
layout_egret_largedoes not emit the oversized picture: 382 and 1022 words for the 2009 and 2023 notices. The failure is specific to Heron.MarkdownDocSerializer(doc, params=MarkdownParams(traverse_pictures=True))recovers the nested text from the existing document (400 and 1035 words), at the cost of also emitting labels inside real figures.
Prototype guard
I tried the fix proposed in the report, implemented as a filter after child assignment in _process_special_clusters: drop a picture cluster when
- it covers more than 0.3 of the page area,
- the union of its non-caption text children covers more than 0.3 of its own area, and
- it has at least 3 such children.
Dropping the cluster returns the children to the regular cluster list, so no new code path is needed downstream.
| Notice | MD words before | MD words after | pictures dropped |
|---|---|---|---|
| 2009-SA-001 | 36 | 397 | 1 (page frac 0.70, text area frac 0.55) |
| 2023-SN-044 | 396 | 1024 | 1 (0.77, 0.78) |
| 2007-SN-008 | 208 | 703 | 1 (0.75, 0.60) |
| 2021-SI-007 | 627 | 627 | 0 |
The real diagrams and logos in each notice are still emitted as pictures.
Against the 247 pictures in the 216 groundtruth DoclingDocument JSONs under tests/data, the rule drops nothing. The text-densest legitimate figures (the arXiv samples, up to 84 nested text labels and text-area fraction 0.72) all sit at or below 0.26 of the page, and the only pictures above 0.3 of the page have text-area fraction at most 0.13. The page-fraction term is what separates the two populations, so a text-density test alone would not be safe.
Related
#3002 has the same signature (native PDF, <!-- image --> placeholders, force_full_page_ocr does not help) and was never traced to this; #357 is the full-page version that the 0.90 guard addressed; #2345 asked why the JSON has the text and the Markdown does not.
Fix is up as #4589: the postprocessor drops a picture that spans at least 30 % of the page when at least three nested non-caption text clusters cover at least 30 % of it. On the four notices with the committed code: 397, 1024, 702 and 627 words (2021-SI-007 unaffected), real diagrams and logos still emitted as pictures, e2e reference outputs unchanged.
Two notes from checking #3002 against the same fix:
- It does not apply there on
main. That document now fails in TableFormer (a runaway structure decode on a 31x33 roster at the decoder's 1024-step budget), and is handled by #4592. Details in https://github.com/docling-project/docling/issues/3002#issuecomment-5996416385. - 2021-SI-007 from the report does not reproduce on
main(627 of 698 words, no oversized picture), so I left it out of the fixture list.
Classification labels added: bug, priority:medium, pdf.
These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.
Another reproducer: bordered text panels at small page fractions (D&D 5.2.1 SRD, 364pp)
Same signature as the traced notices (Hon: picture box over a bordered text panel; text survives in the DoclingDocument as picture children, dropped only by the markdown serializer). Confirmed here: traverse_pictures=True recovers the text (241,046 → 258,594 words, +7.3%, stat-block AC/HP/ability grids restored).
Two data points relevant to #4589's thresholds, from the full-document DoclingDocument JSON (322 picture items):
| metric | value |
|---|---|
| pictures with ≥3 text children | 310 / 322 |
| of those, child-text area ≥30% of the picture bbox | 227 |
| of those, picture page-frac ≥0.30 (PR #4589 guard fires) | 0 |
| page-frac of the misclassified panels | min 0.017 / median 0.044 / max 0.179 |
So the merged guard's 30%-of-page precondition misses this entire document class — stat blocks are dense bordered text panels at ~2–18% of page area.
And the two features don't separate the classes: our misclassified text panels top out at 0.53 text-area fraction (median 0.34), while your arXiv groundtruth legitimate figures reach 0.72 — a text-density-only rule would be inverted for small panels vs labeled figures. Raw prediction confidence would help here, but it isn't exported on the picture items in the document JSON today.
Also: traverse_pictures recovers the content, but nested text items still arrive with source newlines collapsed in orig (multi-line stat lines become one space-joined line) — separate issue; deterministic repair is possible by re-extracting the PDF text layer inside each item's prov bbox (no OCR).
One confirmation of the workaround table: layout_egret_large does not classify the SRD stat-block panels as pictures at all (0–1 text children on its picture items vs Heron's 45 on the same page), so this looks model-specific in both documents.
Ran #4589 against this document; guard fires 0/227 times (max page-frac 0.179), it does not solve our issue.
Example from D&D 5.2.1 SRD, page 259 © Wizards of the Coast LLC, CC-BY-4.0 (original is pdf-native):
Turns into:
Animated Armor
[Picture]
Immunities Poison, Psychic; Charmed, Deafened, Exhaustion, Frightened, Paralyzed, Petrified, Poisoned Senses Blindsight 60 ft.; Passive Perception 6 Languages None CR 1 (XP 200; PB +2)