docling icon indicating copy to clipboard operation
docling copied to clipboard

page_range in DocumentConverter.convert() can cause text out of order

Open linzack opened this issue 1 year ago • 3 comments

Bug

When processing a PDF with DocumentConverter.convert() using a page_range=(start, end) For example, conv_res = doc_converter.convert(source='2206.01062.pdf', page_range=(7, 9)) text from page 9 appeared in the Markdown generated for page 7.

This issue does not occur when processing one page at a time by using page_range=(7, 7) ...

Steps to reproduce

Use the following Python script process the PDF

pipeline_options = PdfPipelineOptions()
pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE
pipeline_options.generate_page_images = True
pipeline_options.generate_picture_images = True

doc_converter = DocumentConverter(
    format_options={
        InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
    }
)
conv_res = doc_converter.convert(source='2206.01062.pdf', page_range=(7, 9))
conv_res.document.save_as_markdown('2206.md', image_mode=ImageRefMode.EMBEDDED)

...

Docling version

Docling version: 2.36.1 Docling Core version: 2.36.0 Docling IBM Models version: 3.4.4 Docling Parse version: 4.0.4 Python: cpython-310 (3.10.12) Platform: Linux-6.6.56+-x86_64-with-glibc2.35 ...

Python version

Python 3.10.12 ...

linzack avatar Jun 11 '25 20:06 linzack

Markdown for page 7 incorrectly includes text from page 9. Image

linzack avatar Jun 11 '25 20:06 linzack

I checked this on current main e3681a613e1be0dd3019bba61b4dc10b92e6e776 using the repository's tests/data/pdf/sources/2206.01062.pdf (SHA256 5dfbd8c115a15fd3396b68409124cfee29fc8efac7b5c846634ff924e635e0dc). The filename matches the report, but I cannot confirm it is byte-identical to your input.

Setup: one Docker run on Linux ARM64 (CPU), Python 3.10.22, Docling 2.147.0, docling-core 2.106.0. I used the default PDF pipeline (Heron layout, TableFormer accurate, RapidOCR with the torch backend), with device="cpu" and 2 threads, generate_page_images=True, generate_picture_images=True, and Markdown saved with ImageRefMode.EMBEDDED. I converted page 7, pages 7–9 and the whole document, each at the default images_scale of 1.0 and again at 2.0. All six conversions succeeded. This tests current behaviour only, not the reported 2.36.1 setup on x86_64.

No text item combined page 7 with page 9. Every text item that spans pages joins two adjacent pages.

One of those adjacent joins is wrong. In the 7–9 and whole-document outputs, at both scales, the last paragraph on page 7 ("…Between PubLayNet and DocLayNet, these are Picture,") continues with the Table 5 caption from the top of page 8 ("Table 5: Prediction Performance ([email protected]) …"). The real continuation, "Section-header, Table and Text. …", is below Table 5 on page 8. The page assembly labels the caption text, not caption. Converting page 7 alone does not show this.

This does not show that the original report is fixed. The versions and layout model differ from yours. Could you share the original PDF (or its SHA256), the IMAGE_RESOLUTION_SCALE you used, and the exact text that appeared in the wrong place? That would show whether you saw page 9 text, or this page 8 caption problem.

leninworld avatar Nov 05 '26 03:11 leninworld

Classification labels added: priority:medium, pdf.

These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.

github-actions[bot] avatar Nov 16 '26 16:11 github-actions[bot]