Skip to content

LearnIngest & extract

Layout analysis

Document layout analysis · Page segmentation

Finding the regions on a page and labeling each one, such as heading, paragraph, table, figure, caption or footer, before reading the text inside them.

In DocSlurpIllustrated explainer

On this page
Layout analysis labels every region of a page before its text is readA report page is divided into eight numbered regions: 1 page header, 2 section heading, 3 paragraph, 4 table, 5 figure, 6 caption, 7 paragraph beside the figure, 8 page footer. Each label decides the treatment: the header and footer are dropped from the text and kept as metadata, the heading becomes the heading path "4.2 Margin plan", paragraphs are chunked as text, the table goes to a table extractor, the figure goes to a vision model, and the caption is attached to its figure. A box below contrasts what happens without labels: the table flattens into one line of words and numbers, the footer is indexed 40 times, and figure labels are spliced into the paragraph.page header1section heading2paragraph3table4figure5caption6paragraph7page footer8REGIONWHAT HAPPENS TO IT1page header→dropped from text, kept as metadata2section heading→## 4.2 Margin plan3paragraph→text, chunked under 4.24table→table extractor: rows and headers5figure→vision model writes a description6caption→attached to figure 37paragraph→text, chunked under 4.28page footer→dropped: it repeats on all 40 pagesWithout layout labelstable → Metric Plan Forecast Revenue $43.0M…footer → indexed 40 times, once per pagefigure labels → spliced into the paragraph
Layout analysis decides what each region is, and that decides how it is read. The numbers give the reading order. Headers and footers leave the text, the table goes to a table extractor, the figure to a vision model, and the heading becomes the section path for every chunk under it. Without the labels, all eight regions become the same thing: a run of words.

The problem: everything on the page is text

Page 12 of growth-plan-2027.pdf has a heading, two paragraphs, a table of margin targets, an expansion diagram with a caption, and a running footer: “Confidential · Growth plan FY2027 · Page 12”.

Run a plain text extractor over it and every one of those becomes the same thing, a run of words. The table turns into one long line, “Metric Plan Forecast Ahead Revenue $43.0M $48.2M 12% Operating margin 20% 24% 4 pts”. The diagram’s labels (“New York”, “London”, “Q2 2027”) land in the middle of a paragraph. The footer appears on all 40 pages, so 40 chunks now contain the words “Confidential” and “Growth plan”, and any query mentioning the plan matches all of them a little.

Each word was extracted correctly. What went wrong is that nothing knew what kind of thing each word belonged to.

What layout analysis does

Layout analysis finds the regions on a page and labels each one before anyone reads the text inside. The output is a list of boxes, each with a label and usually a confidence:

Region Label What the pipeline does with it
“4.2 Margin plan” section heading starts a new section; becomes the heading path of later chunks
Two text blocks paragraph ordinary text, chunked normally
Grid of cells table sent to table extraction
Diagram figure captioned, described by a vision model, or skipped
“Figure 3: Expansion timeline” caption attached to its figure
“Confidential · … · Page 12” page footer dropped from the text, kept as metadata

The labels decide how each region is handled. That is the whole point: different regions need different extractors, and some need none.

Two ways to find regions

Rules over geometry. If the PDF has a text layer, every word already has a position, a font and a size. Simple rules go a long way. Larger, bolder text on its own line is probably a heading. Text that repeats at the same position on every page is a header or footer. One concrete rule set, used by DocSlurp’s native PDF engine, classifies a block by where its center falls:

  • center in the top 10% of the page height: header
  • center in the bottom 10%: footer
  • center in the outer 15% of the width: left or right sidebar
  • anything else: body

On a US Letter page (612 × 792 points, with y measured down from the top) that means a header above y = 79.2, a footer below y = 712.8, and sidebars left of x = 91.8 or right of x = 520.2. A footer line centered at y = 760 is a footer; a margin note centered at x = 50 is a left sidebar.

Learned detectors. Rules need a text layer and a conventional design. A learned detector works on the page image instead. It is an object-detection model, the same kind that finds cars in photos, trained on pages where people drew and labeled boxes. DocLayNet, a widely used training set, has about 80,000 pages labeled with 11 classes: caption, footnote, formula, list item, page footer, page header, picture, section header, table, text and title. Because it looks at pixels, a detector works on scans as well as born-digital PDFs.

Most production systems mix the two: a detector proposes regions and the text layer supplies exact words and positions inside them.

Where it breaks

  • Unusual designs. Rules assume conventions. A report whose title sits in the top 10% of page 1 gets labeled “header” and dropped. A full-bleed photo with text over it confuses both approaches.
  • Training-set mismatch. A detector trained on papers and annual reports has seen few receipts, slides or forms. It will still output boxes with confident labels; they will just be wrong more often.
  • Borderless tables. A table with no ruling lines looks a lot like several narrow paragraphs. If the detector misses it, the cells are read as prose.
  • Overlaps and splits. Boxes can overlap, or one paragraph can be split into two. A table that continues onto the next page is detected as two unrelated tables.
  • Labels are not order. Knowing that a page has two paragraph regions side by side does not say which to read first. That is reading order, the next step.

When it matters

For a novel or a plain memo, layout analysis adds little: one column of paragraphs, no tables. It earns its cost on reports, papers, manuals, forms and slides, where structure carries meaning. The cheapest wins usually come first: drop repeated headers and footers, keep headings for chunking, and route tables and figures to specialists. A page-level decision about which pages need the expensive treatment is page routing.

In DocSlurp

In DocSlurp

No single layout model runs on every page. When a PDF has table pages, or a project enables pdfRegionExtraction, extraction also runs Unstructured's hi_res partitioner, which uses a layout detection model (core/worker/src/stages/extract-markdown.ts). The native PDF engine, when installed, classifies blocks as header, footer, sidebar or body by position (core/worker/src/native-pdf/regions.ts).

Sources

Jump to