Reading order detection is the task of arranging the text regions of a document page into the sequence a human reader would follow, such as column by column, with captions next to their figures and footnotes at the end. In Document AI, it sits between layout analysis and downstream extraction: OCR and layout models find where text is, and reading order detection decides in which order that text should be read.
Without correct ordering, a two-column article becomes a jumble of interleaved lines, and a language model receives text that is accurate word by word yet incoherent as a whole. This makes reading order a hidden but decisive factor in PDF parsing, document-to-Markdown conversion, retrieval and document question answering.
How reading order detection works
Reading order detection takes as input a set of detected layout elements, usually text blocks, titles, tables, figures and captions with their bounding boxes, and outputs a permutation of those elements. Some systems also order lines inside each block, which matters for rotated or vertical text.
The process usually runs in three stages. First, a layout analysis model segments the page into regions. Second, the system builds pairwise or global relations between regions, for example that one block precedes another. Third, it resolves those relations into a single sequence, often with a graph algorithm or a sorting procedure that respects the predicted precedences.
The table below shows the main signals that ordering methods use.
| Signal | What it indicates | Where it fails |
|---|---|---|
| Geometric position | Top-to-bottom, left-to-right flow | Multi-column and magazine layouts |
| Column structure | Finish one column before the next | Spanning headlines and inset boxes |
| Semantic continuity | A sentence continues in the next block | Lists, tables and fragmentary text |
| Region type | Captions follow figures, footnotes come last | Unconventional design templates |
| Visual cues | Separators, whitespace, font changes | Scanned pages with noise or skew |
Approaches to reading order detection
Methods range from simple geometric heuristics to learned models that combine layout and language. The right choice depends on how varied the documents are and how much labeled data is available.
| Approach | How it works | Strength | Weakness |
|---|---|---|---|
| XY-cut | Recursively splits the page along whitespace gaps | Fast and transparent | Breaks on complex or irregular layouts |
| Rule-based topological sorting | Builds precedence rules from geometry and sorts | Handles standard columns well | Rules multiply for each new template |
| Learned pairwise ranking | Classifies whether block A precedes block B | Adapts to training data | Needs labeled order data |
| Sequence models on layout | Layout-aware transformers predict the order directly | Uses text and position together | Higher compute cost |
| End-to-end vision-language models | Generate text in reading order from the image | No separate ordering step | Errors are hard to diagnose |
Learned approaches gained ground once datasets with explicit order annotations became available; ReadingBank, with about 500,000 Word-derived pages, is a well-known example. Models such as LayoutReader treat ordering as a sequence-to-sequence problem over tokens and boxes, while toolkits such as Docling apply ordering as a dedicated pipeline stage after layout detection.
Why reading order matters for downstream tasks
Reading order errors propagate silently. The OCR text may be perfect, so character error rate looks excellent, yet the extracted document is useless for any task that depends on meaning. The comparison below shows the effect on common downstream uses.
| Downstream task | Effect of wrong order | Severity |
|---|---|---|
| Document-to-Markdown conversion | Paragraphs interleave across columns | High |
| Retrieval-augmented generation | Chunks mix unrelated passages | High |
| Document question answering | Answers cite fragments out of context | High |
| Key information extraction | Labels separate from their values | Medium |
| Full-text search | Phrase queries fail across broken lines | Low to medium |
For retrieval pipelines, the practical rule is to verify ordering before tuning chunking or embeddings. Optimizing later stages cannot repair text whose sentences were split and recombined incorrectly.
Difficult layouts and common failure modes
Most reading order errors come from a small set of recurring layout patterns. Newspapers, scientific papers, forms and slide decks each challenge simple top-to-bottom logic in different ways.
- Multi-column pages with spanning elements: a title or figure across both columns breaks naive column splitting.
- Sidebars and pull quotes: inset boxes interrupt the main flow and should be read separately.
- Tables and forms: cells need row-wise or key-value order, not visual line order.
- Right-to-left and vertical scripts: Arabic, Hebrew and vertical Japanese reverse the default assumptions.
- Headers, footers and page numbers: repeated elements must be excluded or placed consistently.
- Content flowing across pages: a paragraph that continues on the next page needs cross-page linking.
Evaluation typically compares the predicted order with a human reference using edit-distance or rank-correlation measures such as Kendall’s tau or BLEU on the ordered text. A key caveat is that some pages have more than one acceptable order, for example independent sidebars, so strict metrics can understate quality.
Choosing a reading order strategy
The most reliable strategy is to match the method to document variability. Uniform, machine-generated PDFs rarely need a learned model, whereas heterogeneous scanned archives usually do.
| Situation | Recommended approach | Reason |
|---|---|---|
| Digital PDFs with a reliable text layer | Use embedded structure, check with geometry | Tagged PDFs often encode order already |
| Single-column business documents | Geometric sorting | Simple layouts rarely need learning |
| Mixed scientific and news layouts | Learned layout-aware model | Heuristics fail on varied columns |
| High-value archives with audits | Learned model plus human review | Errors are costly and must be traceable |
In plain words
Reading order detection works out which part of a page comes first, second and third. People do this without thinking. We read a newspaper column to the bottom, then jump to the next one.
A computer only sees boxes of text scattered on a page. Reading order detection gives those boxes the right sequence. Without it, the text reads like two conversations mixed together.
A real-world example
A university library digitizes 40 years of a two-column scientific journal and wants to offer a chatbot that answers questions about the articles. The first pipeline uses OCR with a simple top-to-bottom sort. Character accuracy is high, but many chunks mix the left and right columns, so the chatbot often quotes half-sentences from unrelated paragraphs.
The team adds a learned reading order stage after layout detection and treats figure captions, footnotes and page headers as separate elements. On a hand-checked sample of 300 pages, the share of pages with fully correct reading order rises substantially, and answer quality improves without any change to the language model or the embeddings. The library also flags pages with low ordering confidence, such as special issues with unusual layouts, for manual review before indexing.