Skip to content
AgenticAIWiki
  1. Learn
  2. Part 4
  3. 27. Parsing complex documents
  4. 27.2

Lesson 27.2 · 2 of 5 · 6 min read · Reviewed 24 Nov 2026

Layout-aware parsing tools

By the end, you can

  • Describe the main kinds of document parsing tools and what each outputs.
  • Choose a parsing approach for a given set of documents.

From a string to elements

The simplest extractor gives you one long string per page. A layout-aware parser gives you a list of elements, each with a type, its text, the page it came from and where it sat:

[{"type": "heading",   "text": "3. Refunds",                    "page": 4, "bbox": [72, 90, 300, 110]},
 {"type": "paragraph", "text": "The refund window is 30 days...", "page": 4, "bbox": [72, 120, 290, 200]},
 {"type": "table",     "text": "| Plan | Window |\n|---|---|\n| Basic | 30 days |", "page": 4},
 {"type": "footer",    "text": "Annual report, page 4",          "page": 4}]

Now you can drop footers, keep tables whole, prepend the heading to each paragraph chunkChunking: Splitting documents into smaller passages before embedding and indexing them., and cite page 4. That structure is what makes chunking (chapter 23) work well on real documents.

The kinds of tools

Kind How it works Examples Good for
Text-layer extractors Read the characters stored in the PDF pypdf, pdfminer.six, PyMuPDF Clean, single-column digital files; fast and cheap
Layout analysis toolkits Models detect regions (columns, headings, tables) on each page, then read in order Docling, Unstructured, Marker Reports, papers, manuals with mixed layouts
OCR engines Read text from page images Tesseract, and OCR inside the toolkits above Scans and photos with no text layer
Cloud document services Hosted OCR plus layout, tables and forms Services from the major cloud providers Large volumes of forms and invoices, if data may leave your network
Vision-language models Send the page image and ask for structured output Most multimodal models Hard pages: charts, odd layouts, handwriting (27.4)

These are examples, not endorsements. Most toolkits combine several of these internally: they use the text layer where it exists and fall back to OCR where it doesn’t.

Choosing

Ask three questions about your documents:

  1. Is there a text layer? If many pages are scans, you need OCR or page images.
  2. How complex is the layout? Columns, sidebars and tables need layout analysis. A plain contract may not.
  3. Can the data leave your machines? If not, prefer tools you run locally over hosted services (28.4).

Then add cost and speed. Text-layer extraction handles many pages per second on a laptop. Layout models are slower and may want a GPU for big batches. VisionVision: A model’s ability to read and reason about images, such as screenshots, charts and photos. models are the slowest and use the most tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id..

Compare on your own sample

Don’t choose from a feature list. Take 20 representative pages, run two or three parsers, and score the output:

Check How
Reading order correct Read it; count pages with interleaved columns
Tables intact Compare a few cells with the original
Noise removed Count repeated headers and footers left in
Page numbers kept Every element carries one

Then run your retrieval evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. (chapter 26) on chunks from each parser. The parser that wins on retrieval is the one to keep.

Common mistakes

  • Running OCR on every page, including ones with a good text layer: slower and often less accurate.
  • Throwing away element types and keeping only text, losing what makes the parse useful.
  • Choosing a hosted service without checking whether the documents are allowed to leave your network.

Key points

  • Parsers range from plain text-layer extractors to layout models, OCR engines, cloud document services and vision-language models.
  • Layout-aware parsers return typed elements (heading, paragraph, table, figure) with page numbers and positions, not one long string.
  • Pick by your documents: clean digital text needs little; columns, tables and scans need layout analysis or OCR.
  • Compare parsers on a sample of your own documents and keep the element type and page with every chunk.
Hands-on labOn your own machine

Compare two parsers on your own PDFs

Run a plain text-layer extractor and a layout-aware parser on the same real documents and decide, with evidence, which one to use.

You will have: A scoring table for 5 documents and 2 parsers (reading order, tables, noise, page numbers) and a one-paragraph recommendation.

Steps

  1. Pick five PDFs that look different: two-column, tables, a scan, slides exported to PDF and a plain contract. Use documents you are allowed to process on your machine.
  2. In a fresh virtual environment, install pypdf and one layout-aware toolkit (for example Docling or Unstructured) by following their install pages.
  3. Extract each PDF with both tools, keeping the page number for each piece of output, and save the results as text or JSON files.
  4. Score each output on four checks: reading order correct, tables intact, headers and footers removed, page numbers kept.
  5. Note time per page for each tool, and pages that came back empty (they need OCR).
  6. Write a short recommendation, and plan to confirm it with your retrieval eval (chapter 26).

Done when

  • The table has 5 x 2 rows with all four checks filled in.
  • Empty pages are counted per tool.
  • The recommendation cites at least two scores from the table.

Docs: pypdf documentation · Unstructured documentation · Auer et al., Docling Technical Report (arXiv)

Quick checkHalf of an archive is scanned paper letters with no text layer. A text-layer extractor returns empty strings for them. What should you add?
How sure are you?
Pick an answer and how sure you are