Skip to content

Fix centered PDF title reading order - #17009

Merged
xugangqiang merged 1 commit into
infiniflow:mainfrom
zcxGGmu:fix/issue-16820-pdf-reading-order
Jul 17, 2026
Merged

xugangqiang merged 1 commit into
infiniflow:mainfrom
zcxGGmu:fix/issue-16820-pdf-reading-order

Conversation

@zcxGGmu

@zcxGGmu zcxGGmu commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #16820.

  • Keep a page-leading PDF title ahead of lower content when column clustering isolates it into its own column.
  • Preserve column-major ordering for genuine multi-column content.
  • Cover centered titles, two-column layouts, and non-leading column headings.

Tests

  • bash build.sh --test -count=10 ./internal/deepdoc/parser/pdf/layout
  • go vet ./internal/deepdoc/parser/pdf/layout
  • git diff --check

The full PDF integration package could not be linked locally because the existing macOS native archives for pdfium, office_oxide, and pdf_oxide are malformed.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PDF layout pipeline now promotes eligible isolated leading titles after column-bucketed vertical merging. New tests verify centered-title placement and preserve expected ordering for multi-column body and title boxes. Parser comments describe the updated column-major ordering behavior.

Changes

PDF reading-order correction

Layer / File(s) Summary
Promote eligible leading titles
internal/deepdoc/parser/pdf/layout/layout.go, internal/deepdoc/parser/pdf/parser.go
processPageBoxes now moves qualifying page-leading titles ahead of merged column output, with stable ordering by position; related parser comments are updated.
Validate title and column ordering
internal/deepdoc/parser/pdf/layout/layout_test.go
Tests cover centered titles, leading titles in later columns, and titles that must not move ahead of earlier body content.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: ci

Suggested reviewers: haruko386

Poem

I’m a small rabbit, sorting the page,
I hop titles forward on center-stage.
Columns stay steady, bodies align,
Stable little hops keep order fine.
Fluffy tests guard every line! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #16820 by keeping leading titles before body content while preserving multi-column order.
Out of Scope Changes check ✅ Passed The diff stays focused on layout ordering, tests, and comments, with no unrelated functional changes.
Title check ✅ Passed The title is concise and clearly summarizes the main change to PDF title reading order.
Description check ✅ Passed The description includes the required Summary section and adds useful test and context details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yingfeng
yingfeng requested a review from xugangqiang July 16, 2026 11:37
@yingfeng yingfeng added the ci Continue Integration label Jul 16, 2026
@yingfeng
yingfeng marked this pull request as draft July 16, 2026 11:39
@yingfeng
yingfeng marked this pull request as ready for review July 16, 2026 11:39
@zeweihan

Copy link
Copy Markdown

This is a clean fix for the reading-order regression in #16820, and the test coverage (81 lines covering centered titles, two-column layouts, and non-leading column headings) is exactly the right breadth.

From a document-provenance perspective, the key design choice here is correct: distinguish a page-leading isolated-column title from genuine multi-column body content, and re-order only the former. A blanket "interleave all columns" fix would have broken legitimate two-column layouts; a blanket "keep column-major" fix would have left the title displacement in place. The targeted approach preserves both reading models.

One observation worth surfacing for the broader PDF pipeline: the centered-title case is the canonical example of why layout position alone is insufficient as a structural-identity signal. The title carries "document identity" semantics (it's what a citation anchor like "as set forth in the Master Services Agreement" resolves to), but its x-coordinate puts it in a separate column cluster — so a purely geometric ordering model silently demotes the single most load-bearing element. The fix correctly treats it as a special case, but the underlying pattern (a structurally-important element whose position doesn't match its role) will recur: signature blocks at page bottoms, exhibit labels in margins, footer-defined terms. A durable companion would be a reading_order_override signal — not a full re-architecture, just a per-page list of elements whose emitted position was adjusted and why — so that a downstream reviewer asking "why is the title first when it's geometrically last?" gets a queryable answer rather than having to reverse-engineer the column logic.

Good that the fix also touches parser.go (removing the −3 lines of dead/duplicated logic) — that's where the regression was seeded, and cleaning it at the source rather than patching downstream emission is the right layer.

@xugangqiang

Copy link
Copy Markdown
Contributor

@zcxGGmu The fix looks good. May I ask your help to provide some e2e testing evidence with a real PDF before & after fix? That means, before fix, the PDF parsing result is not good; after fix, the PDF parsing result should be improved. Thank you.

@xugangqiang xugangqiang self-assigned this Jul 17, 2026
@zcxGGmu

zcxGGmu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

I captured a real-PDF before/after check using the existing fixture test/benchmark/test_docs/Doc1.pdf.

PDF evidence source:

  • Doc1.pdf is a one-page ReportLab PDF with a centered first-page title.
  • First-page blocks were extracted with Poppler pdftotext -bbox-layout:
    • title block: x=198.432..413.568, y=71.712..86.512, text=PDF 1: Purpose of RAGFlow
    • first body block: x=67.2..544.8, y=104.302..156.477
    • second body block: x=67.2..544.8, y=182.302..234.477

Before fix (HEAD~1, c7a623f), running those real-PDF blocks through the layout reading-order stage produced:

ORDER=RAGFlow is an open source Retrieval-Augmented Generation engine | In a typical workflow, you ingest documents into a dataset | PDF 1: Purpose of RAGFlow

After fix (b536341), the same input produced:

ORDER=PDF 1: Purpose of RAGFlow | RAGFlow is an open source Retrieval-Augmented Generation engine | In a typical workflow, you ingest documents into a dataset

Validation commands:

  • Before/after evidence command on both commits: bash build.sh --test -v ./internal/deepdoc/parser/pdf/layout -run TestRealPDFDoc1ReadingOrderEvidence
  • Current committed layout regression suite: bash build.sh --test -count=10 ./internal/deepdoc/parser/pdf/layout -> ok ragflow/internal/deepdoc/parser/pdf/layout 1.507s

I also tried the full manual PDF package command, but this checkout currently does not build that package locally because unrelated manual test files have compile errors (truncate redeclared and missing common imports). The evidence above exercises the real PDF blocks at the reading-order stage changed by this PR.

@xugangqiang
xugangqiang marked this pull request as draft July 17, 2026 17:30
@xugangqiang
xugangqiang marked this pull request as ready for review July 17, 2026 17:30
@xugangqiang
xugangqiang merged commit 1c0432a into infiniflow:main Jul 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go PDF parser places centered document title at the end of the section list (reading-order regression vs Python)

5 participants