Reading order detection

On this page 7

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.

SignalWhat it indicatesWhere it fails
Geometric positionTop-to-bottom, left-to-right flowMulti-column and magazine layouts
Column structureFinish one column before the nextSpanning headlines and inset boxes
Semantic continuityA sentence continues in the next blockLists, tables and fragmentary text
Region typeCaptions follow figures, footnotes come lastUnconventional design templates
Visual cuesSeparators, whitespace, font changesScanned pages with noise or skew
Signals used to infer reading order

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.

ApproachHow it worksStrengthWeakness
XY-cutRecursively splits the page along whitespace gapsFast and transparentBreaks on complex or irregular layouts
Rule-based topological sortingBuilds precedence rules from geometry and sortsHandles standard columns wellRules multiply for each new template
Learned pairwise rankingClassifies whether block A precedes block BAdapts to training dataNeeds labeled order data
Sequence models on layoutLayout-aware transformers predict the order directlyUses text and position togetherHigher compute cost
End-to-end vision-language modelsGenerate text in reading order from the imageNo separate ordering stepErrors are hard to diagnose
Main families of reading order methods

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 taskEffect of wrong orderSeverity
Document-to-Markdown conversionParagraphs interleave across columnsHigh
Retrieval-augmented generationChunks mix unrelated passagesHigh
Document question answeringAnswers cite fragments out of contextHigh
Key information extractionLabels separate from their valuesMedium
Full-text searchPhrase queries fail across broken linesLow to medium
Effect of reading order errors on downstream tasks

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.

SituationRecommended approachReason
Digital PDFs with a reliable text layerUse embedded structure, check with geometryTagged PDFs often encode order already
Single-column business documentsGeometric sortingSimple layouts rarely need learning
Mixed scientific and news layoutsLearned layout-aware modelHeuristics fail on varied columns
High-value archives with auditsLearned model plus human reviewErrors are costly and must be traceable
Decision guide for reading order methods

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.