A visual guide to the document pipeline

From pixels
to structure.

Watch a page become labelled regions, recognized content and a reading order you can trust. Then learn to read the JSON it returns.

One page, six passesFig. 01
A scanned page becomes labelled blocks with block_id badges and then structured JSON On the left, a page sketch carries labelled regions with block numbers. On the right, the same regions appear as a JSON block list in reading order, with a caption linked to its figure. b0 · header b1 · doc_title · order 1 b2 · text · order 2 b3 · image b5 · text · order 3 b4 · figure_title b6 · text · order 4 b7 · footer · no order pages[0].blocks {"block_id":1,"type":"doc_title", "order":1} {"block_id":3,"type":"image", "order":null} {"block_id":4,"type":"figure_title", "order":null} caption of b3 · adjacent read in block_id order
Authored sketch. Real JSON carries 25 layout tags, bounding boxes and warnings.
01 / The big picture

Layout. Recognition.
Reading order.

Three ideas carry the whole pipeline: a page is a map of labelled regions, a model fills each region in, and block_id — not position — decides how to read it.

FIND THE REGIONS

Layout labels every region.

PP-DocLayoutV3 scans each page image and returns labelled regions — text, titles, tables, figures, formulas, seals — each with a bounding box in raster pixels.

25 block types from body text to seals and page numbers.
FILL THE REGIONS

Recognition reads each block.

The API crops every labelled region and PaddleOCR-VL on vllm-paddleocr turns it into text, an HTML table, a LaTeX formula or an image reference.

Per-block content lands back on the block, never loose text.
READ IN ORDER

block_id is the order.

Read blocks in block_id order for every page. A null order is a label choice — captions, headers and tables still have a fixed place in block_id.

Never rebuild order from bounding-box coordinates.
Then the evidence

The JSON keeps warnings and per-page errors; captions and footnotes link to their objects by block_id adjacency and label. Markdown is a rendering of the same blocks — not a second opinion.

Read one page yourself
02 / Follow one page

Six passes over
one page.

Follow a single page image through layout, recognition and assembly. Each pass shows what the API or the model contributes.

Inside one pageReady when you are
01 / A page arrives

Every page is
an image first.

Whether the upload is a PDF, a photo or an Office file converted by LibreOffice, the pipeline sees the same thing: rasterized page images inside hard pixel and page budgets. Office input (.docx .pptx .xlsx, legacy .doc .ppt .xls, OpenDocument .odt .odp .ods) is rendered to PDF by LibreOffice first and reports an office_converted info warning.

ocr-api · validation and rasterization
PDF pages rasterize at the configured DPI; Office files become PDF first.
One rasterized pagePAGE IMAGE
Source
PDF · image · Office→PDF
DPI
OCR_PARSE_DPI · 250 default
Pixel cap
25M per page · blocks ≤ 24 pages
Page cap
OCR_MAX_PAGES · 50 · truncates
page 1 of na clean image, nothing read yet
RASTER

Defaults from .env.example. A page over the per-page pixel budget fails closed with 413; pages are processed in blocks of up to 24 pages and 100 M pixels; extra pages are cut with a pages_truncated warning.

02 / Find the regions

Layout draws
the boxes.

PP-DocLayoutV3 scans the page image and returns regions with bounding boxes. At this stage nothing is text — the page is a map of rectangular areas to read.

ocr-api · layout detection on the GPU, beside vLLM
A bounding box says where a region is, never what it says.
?top bandbbox
?title areabbox
?body columnbbox
?grid regionbbox
?bottom linebbox

Illustrative regions. Boxes arrive before any labels or content.

03 / Label each region

One of 25 tags
per block.

Each region receives a layout tag: text, doc_title, table, figure_title, seal, header and nineteen more. The label already decides whether the block gets an order or appears in Markdown.

ocr-api · PP-DocLayoutV3
The label is a contract: it fixes order eligibility and markdown membership.
b0headerno order
b1doc_titleorder 1
b2textorder 2
b3table + figure_titleno order
b4footnoteno order
b5textorder 3

Illustrative labels. order is null by label for captions, headers, footers and page numbers.

04 / Fill each region

PaddleOCR-VL reads
block by block.

The API crops each labelled region and sends it to vllm-paddleocr. Content lands back on its block: prose as text, tables as HTML with rowspan/colspan, formulas as LaTeX, images and seals as image references.

vllm-paddleocr · GPU vision-language inference
Content stays attached to its block — the JSON never returns loose text.
On your NVIDIA GPUPaddleOCR-VL-1.6served as PaddleOCR-VL-0.9B · vLLM 0.32.0 · :8080

▤ Crops in

Labelled regions dispatched within lane and inflight budgets

✎ Content out

Text, HTML tables, LaTeX in $$ … $$, and imgs/img_in_*_box_…jpg references for visual blocks.

Illustrative shapes. Tables keep empty cells empty; formulas stay verbatim.

05 / Rebuild the reading

Order. Relations.
Provenance.

block_id gives the reading order for every block on the page. Captions sit next to their tables and figures in block_id, and footnote markers point to notes on the same page — the JSON has no relations field, so links come from these reading rules. Every block keeps its bbox — p{page}:b{block_id} addresses any fact back to its region.

ocr-api · assembly and normalization
A null order is a label choice, not a missing position — block_id is the order.
b1doc_title — “Invoice 2026-041”order 1
b2text — billing address blockorder 2
b3table + adjacent captionno order
b4footnote — marker † resolvedno order
b5text — totals and termsorder 3

Illustrative blocks. A link without evidence is reported as unresolved, not guessed.

06 / Two renderings, one truth

Markdown and
JSON agree.

Per-page Markdown renders the same blocks for humans: headings, paragraphs, tables, image references. The JSON keeps the full structure — every block, bounding box, warning and page error the Markdown omits.

ocr-api · rendering and delivery
Markdown drops marginal blocks; the JSON never does. Read the JSON for evidence.
One pageblocks[] + markdown
Returned page · illustrative
{"page":1,"blocks":[{"block_id":1,"type":"doc_title",
 "order":1,"bbox":[52,60,398,96],
 "content":"Invoice 2026-041"}],
 "markdown":"# Invoice 2026-041\n…",
 "error":null}
Blocks and Markdown render the same pagewarnings + pages[i].error report gaps
!pages_truncated or a page error means partial evidence — say soalways check

You control the pace. Nothing plays automatically.Illustrative workflow · no requests are sent
Prefer to read? The page in six sentences
  1. Rasterize. Every input becomes page images inside a per-page pixel budget and a page cap, in blocks of up to 24 pages; Office files are converted to PDF first.
  2. Detect. PP-DocLayoutV3 finds the regions and gives each a bounding box.
  3. Label. Each region receives one of 25 tags; the label decides order eligibility and Markdown membership.
  4. Recognize. PaddleOCR-VL reads each region and its content lands back on the block.
  5. Order. block_id numbers every block in reading order; captions and footnotes link to their objects by adjacency and label.
  6. Render. JSON keeps the full structure with warnings and page errors; Markdown renders the same blocks for reading.
03 / Reading-order lab

Read one page
the way the JSON does.

Pick a sample page, then toggle the reading order, the caption links and the marginal furniture. The block list is the order the JSON gives you.

Page anatomy, illustratedAuthored example

An invoice page.

header · b0doc_title · b1text · b2table · b3figure_title · b4text · b5footer · b6
Regions carry data-block-type; badges show block_id when enabled.

The block list — block_id order

  1. b0 · headerorder null

    Aurelia Office Supplies · VAT DE-3321

  2. b1 · doc_titleorder 1

    Invoice 2026-041

  3. b2 · textorder 2

    Billed to Meridian Works, 14 Dock Lane, Bremen

  4. b3 · tableorder null

    3 rows · 2 items · total 162.50

  5. b4 · figure_titleorder null

    Table 1 — Line items

  6. b5 · textorder 3

    Payment due within 14 days.

  7. b6 · footerorder null

    IBAN DE00 1234 · Page copy

The Markdown rendering

# Invoice 2026-041

Billed to Meridian Works,
14 Dock Lane, Bremen

| Item | Qty | Amount |
|---|---|---|
| Desk lamp | 2 | 118.00 |
| Cable set | 5 | 44.50 |

Table 1 — Line items

Payment due within 14 days.

The lab reads authored data embedded in this page. A real run can differ — use it to practise the reading rules, not to predict output.

04 / The 25 labels

Every block has
a contract.

One row per layout tag. order says whether the block is numbered; markdown says whether the page Markdown contains it. Both are decided by the label, not by position.

Layout tags from PP-DocLayoutV3 via PaddleOCR-VL 1.6 — as documented in the smart-document-reader skill. Unknown tags pass through unchanged; report them with their tag.
LabelWhat it isordermarkdownHow to read it
abstractAbstractnumberedyesTyped section before the body, in papers.
algorithmCode or algorithmnumberedyesA code block; markdown carries no fences. Pseudocode can instead arrive as display_formula.
aside_textSide or margin textnullnoPage metadata — arXiv identifiers, side navigation. The chunker can keep it in body chunks; set it apart when reading.
chartChartnullyesMention presence, caption and source; never state values.
contentTable of contentsnumberedyesIts page numbers are printed labels, not OCR page indexes.
display_formulaDisplay formulanumberedyesKeep the $$ … $$ LaTeX verbatim. Matrices and pseudocode land here too.
doc_titleDocument titlenumberedyesThe top heading. A second one is often a subtitle or a separate article — confirm from content.
figure_titleFigure, table or chart captionnullyesUsually adjacent in block_id to its object; confirm by label. An isolated trailing caption may be unresolved.
footerPage footernullnoCopyright, venue, disclaimers, funding. Report repeats once.
footer_imageFooter imagenullnoA logo. Mention it with the adjacent footer; never describe it.
footnoteFootnotenullnoLink its marker to body text on the same page; a note can lack a marker.
formula_numberEquation numbernumberednoUsually the display_formula just before it in block_id; after a text block it numbers an equation inside that prose.
headerPage headernullnoRunning title, date, publication name — page metadata.
header_imageHeader imagenullnoA logo; it can sit outside the top band. Never describe it.
imageImagenullyesMention presence and caption; never describe. Markdown shows an imgs/img_in_image_box_…jpg reference.
inline_formulaInline formulanumberedyesMostly standalone; inside prose, math stays inside text as $ … $. Adjacent fragments can be one split formula — flag it.
numberPrinted page numbernullnoA printed label such as "12" or "C7" — not the page index.
paragraph_titleSection headingnumberedyesLevel only from explicit numbering. Also receives "References" and slide titles; bylines are usually text.
referenceReferences region——Dropped by the pipeline before recognition; bibliography arrives as reference_content.
reference_contentBibliography entrynumberedyesOne entry per block, starting "[n]" or "n." — keep the numbering.
sealSeal or stampnumberedyesMention presence only; the stamp text is not read.
tableTablenullyesHTML <table> with rowspan/colspan; empty cells stay empty. Flag tables continued on the next page.
textBody textnumberedyesThe body. An empty block sharing a group_id keeps its text in that group — it still carries an order.
vertical_textVertical textnumberedyesCJK vertical columns; block_id ran right to left on the pages observed — flag any inversion.
vision_footnoteNote under a figure or tablenullyesSource, photo credit, legend or URL for the object just before it.

Condensed from references/block-types.md ↗ — the skill file is the owning reference and adds observed variants per tag.

05 / Division of labour

Four workers.
One page.

Each pass in the journey belongs to a different part of the stack. Knowing who does what tells you where a surprising output can come from.

ocr-api · FastAPI

The API validates and orchestrates

Admission budgets, Office conversion, rasterization, dispatch and final assembly all live in the API. Per-page failures become structured page errors instead of a failed request.

Owner of warnings — check warnings[] and pages[i].error first.
PP-DocLayoutV3 · pipeline backend

Layout runs on the API side

Region detection and labelling happen inside the OCR API's pipeline, not on the model server. The 25 tags and every bounding box come from this stage.

A map, not a reading — regions exist before any content.
vllm-paddleocr · NVIDIA GPU

PaddleOCR-VL recognizes

The vision-language model reads each cropped region and returns text, HTML tables, LaTeX or image references. Recognition needs the GPU; a page that fails VLM recognition surfaces as a page error.

Per-block content under lane, slot and memory budgets.
PaddleOCR tokenizer · CPU

The tokenizer counts

The local PaddleOCR-VL tokenizer already counts each block's content_tokens during /parse and sums them in the top-level usage. When the same JSON is later chunked for RAG, the chunker reuses that tokenizer on CPU — no second GPU inference. Same input and options give byte-identical chunks.

Deterministic — see the RAG chunking guide ↗.
06 / Practical trade-offs

Three dials
shape the result.

Parse options trade fidelity against time and payload size. They are per-request choices — the template defaults suit most first reads. Two more shape the payload: output (markdown, json or both, default both) chooses which of markdown and blocks each page carries, and json_rag=true adds a separate top-level json_rag export, null unless requested or when json_rag_failed is reported.

Dial / Coverage vs time

max_pages and dpi

max_pages caps how many pages are parsed — a truncated result sets pages_truncated, so say the document is partial; a value above OCR_MAX_PAGES is rejected with 422. dpi (50–400) sets raster density for PDF and Office pages: higher reads small print better and costs more time per page, inside the 25M per-page pixel cap. On image input it is ignored with a dpi_ignored warning.

Dial / Table shape

table_format

Tables can render as html (the API default, with rowspan/colspan spans) or markdown; the console preselects markdown · pipes. HTML keeps merged cells exact; markdown tables are easier to quote but lose span structure.

Dial / Visual evidence

include_images

Off by default in the API; the console's include figures box starts checked. When enabled, each page carries base64 PNG crops in images with matching image_names; a crop over OCR_MAX_EMBEDDED_IMAGE_BYTES is skipped with an images_truncated warning. When off, visual blocks still appear as imgs/img_in_*_box_… references in Markdown and as typed blocks in JSON.

Try it on a real page

Parse a small document in the console, then compare the block list with this page's lab. The launcher prints the console URL:

Windows · PowerShell 7
pwsh .\stack.ps1 urls

Linux / macOS · Bash
bash stack.sh urls

07 / Glossary & further reading

A little less jargon.
One level deeper.

Terms this page uses, and the owning documents that define the exact behavior.

What is block_id?

The per-page index of a block and its reading order. Read blocks[] in block_id order; never re-sort by bounding box. p{page}:b{block_id} is the provenance address of any fact.

Why is order null?

order is null by label — table, figure_title, image, chart, vision_footnote, footnote, header, footer, number, aside_text, header_image and footer_image never get one. Null means "this label is not numbered", not "unplaced": the block still has its block_id position.

What is bbox?

A block's bounding box in raster pixels, origin top-left: [x0, y0, x1, y1]. Use it to point back at the page or to crop a region for a focused /ocr task — not to reconstruct reading order.

What is a relation?

A link between blocks — a caption to its table or figure, a footnote marker to its note. The /parse JSON has no relations field: resolve links from block_id adjacency and labels, as the smart-document-reader skill describes. The RAG chunker records them as relations on chunks, with status unresolved when evidence is missing — never invented.

What does markdown contain?

A rendering of the same blocks: headings, paragraphs, tables and image references. Marginal furniture — headers, footers, page numbers, side text — never reaches it, and neither do footnotes or equation numbers. When output="markdown" was requested, blocks can be null and markdown is the only source.

What is a warning?

A structured note about degraded evidence — truncation, a partial page, pages left unprocessed when the time budget ran out, a skipped element, a page whose layout scored low or a table read in a loop. Top-level warnings[] plus per-page error fields tell you how complete a result is before you trust it. Each warning carries code, severity (warning or info), message, target and details. Codes: pages_truncated, pages_unprocessed, page_failed, office_converted, tables_spans_expanded, images_truncated, json_rag_failed, dpi_ignored, layout_low_confidence, table_suspect. The last two name a page that has no error and may still miss text; table_suspect says in details.reread whether a second reading replaced the block (kept: it passed the checks and is usually whole, not surely) or its text is still cut short (rejected, skipped, off). The json_rag export lists those pages in metadata.low_layout_confidence_pages and metadata.suspect_table_pages; its chunks carry no mark.

What does 503 ocr_disabled_archive_only mean?

The stack runs in archive-only mode: vllm-paddleocr is not started and no GPU is reserved, so /parse, /ocr and /parse/chunks refuse before reading the upload, and /health reports mode=archive_only with vllm=disabled while healthy. Stored archives, /chunk on saved JSON and Office previews still work; OCR comes back when the stack is started in OCR mode again: no --archive-only / -ArchiveOnly flag, and OCR_ARCHIVE_ONLY unset or false in .env.

What is an element task?

/ocr takes one image and one task — ocr, table, formula, chart, spotting or seal — and returns result, task, boxes, model_name, processing_time_ms and warnings. Spotting boxes are axis-aligned envelopes in normalized 0–1000 units, not pixels. When generation stops at the token limit the partial result still arrives with HTTP 200 and a generation_truncated warning; the server never retries it.

What is group_id?

A grouping hint between neighbouring blocks — an empty text block can share a group_id with the block holding its text. It is not a block_id and does not change the reading order.

What is page furniture?

The marginal labels: header, footer, number, aside_text, header_image, footer_image. They describe the page, not its body — keep them as metadata, out of quotations.

Go one level deeper.

Checked against the repository's owning references. This page is an offline explanation; it does not inspect your machine, connect to your services, or change their configuration.

08 / Questions

Read the JSON
like evidence.

Match each surprise in a result to the field that explains it.

Why is markdown null or partial?

Check the request's output and top-level warnings. When blocks is null the parse ran with output="markdown": the Markdown is the only source — cite by page, say that headers, footers, page labels and side text are absent, and re-parse with output json or both if you need the structure.

Why does a block have empty content?

An empty text block sharing a group_id with a non-empty block keeps its text there — read the group, not the single block. Empty visual blocks (image, chart, seal) are normal: mention presence and captions, never describe or quote pixel content.

One page failed — is the rest usable?

Yes, with a caveat. A per-page error means that page is unreliable or missing while the others returned normally; pages_truncated means only the first pages were parsed at all; pages_unprocessed lists pages never reached before the time budget ran out, while the finished pages still return. Name the gap and never call a partial result the whole document.

A caption points at nothing — what happened?

A figure_title without an adjacent object is only a possible continuation — its figure or table may live on the next page. Verify matching evidence there; otherwise report the association as unresolved rather than guessed.

Should I rebuild order from bounding boxes?

No. block_id already is the reading order — including tables, captions and vertical text, which ran right to left on the pages observed. Coordinates are provenance for pointing back at the page, not a sort key.

Why does one page show two doc_titles?

A page can genuinely hold two articles, or the second doc_title is a subtitle or subject line. Confirm from the content around it before treating it as the title.

09 / Keep going

Put the blocks
to work.

The next guide turns this JSON into token-bounded chunks that keep their provenance.