Document-to-Markdown conversion is the process of transforming documents such as PDFs, scanned pages, slide decks and word-processor files into Markdown text that preserves their logical structure: headings, paragraphs, lists, tables, formulas and reading order. In Document AI, it has become a standard preprocessing step for retrieval-augmented generation, search indexing and large language model pipelines, where it is often described simply as PDF to Markdown.
Markdown is attractive because it is lightweight, human-readable and familiar to language models, which saw large amounts of it during training. A good conversion keeps the structural signals a reader would use, such as which line is a section title or which cells belong to one table row, while discarding visual noise like page headers, footers and decorative layout.
How document-to-Markdown conversion works
A conversion pipeline recovers logical structure from visual or binary layout and then serializes it as Markdown. The exact steps depend on whether the source has a usable text layer, but most modern systems follow the same broad sequence.
- Text acquisition: extract the embedded text layer from digital files, or run OCR on scanned images.
- Layout analysis: detect regions such as titles, body text, tables, figures, captions and footnotes.
- Reading order detection: arrange regions in the order a human would read them, including multi-column pages.
- Element recognition: reconstruct table cells, convert formulas to LaTeX and identify list hierarchy.
- Serialization: emit Markdown syntax, such as
#headings, pipe tables and fenced code blocks.
The hardest step is usually reading order and table structure, because PDF files store glyphs at positions on a page rather than paragraphs or cells. A two-column scientific paper, for example, can easily be read across columns if the layout model fails, producing interleaved, meaningless sentences.
Main conversion approaches
Converters fall into three broad families: rule-based parsers, modular pipelines with specialized models, and end-to-end vision-language models that read a page image and write Markdown directly. Each makes a different trade-off between speed, cost and robustness.
| Approach | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Rule-based text extraction | Reads the PDF text layer and applies heuristics | Very fast, cheap, deterministic | Fails on scans and complex layouts |
| Modular ML pipeline | Layout detection, OCR and table models combined | Good structure, controllable steps | More components to tune and maintain |
| End-to-end vision model | Page image in, Markdown text out | Handles formulas and unusual layouts | Slower, costly, can hallucinate text |
| Hybrid with LLM cleanup | Pipeline output refined by a language model | Fixes small structural errors | Adds cost and possible content drift |
Open-source tools such as Docling represent the modular approach, research models such as Nougat show the end-to-end approach for scientific papers, and hosted services such as LlamaParse combine parsing with language model postprocessing.
Which document elements survive conversion
Markdown is intentionally limited, so some document features map cleanly and others are lost or approximated. Knowing these limits helps teams decide when Markdown is enough and when a richer format such as JSON with coordinates is needed.
| Document element | Markdown representation | Fidelity |
|---|---|---|
| Headings | Hash-prefixed heading levels | High if levels are detected correctly |
| Lists | Bulleted or numbered items with indentation | High for simple nesting |
| Simple tables | Pipe tables with a header row | Good |
| Merged or nested cells | Flattened pipe table or embedded HTML | Low, structure often lost |
| Mathematical formulas | Inline or block LaTeX | Good with specialized models |
| Images and charts | Image reference or generated description | Content lost unless described |
| Fonts, colors, exact positions | Not represented | Discarded by design |
Because pipe tables cannot express merged header cells, financial statements and scientific tables are frequent sources of error. Many pipelines therefore keep complex tables as embedded HTML or separate structured output while using Markdown for running text.
Role in retrieval and language model pipelines
In retrieval-augmented generation, conversion quality directly limits answer quality: a chunk that mixes two columns or breaks a table cannot be retrieved or interpreted correctly. Markdown headings also provide natural boundaries for structure-aware chunking, where each chunk carries its section path as context.
Compared with plain text extraction, Markdown keeps hierarchy and table alignment, and compared with full layout JSON, it is far more compact, which reduces token counts and inference cost when documents are passed to a language model. It is less suitable when downstream steps need bounding boxes for citations or redaction, because Markdown carries no page coordinates.
Quality evaluation and common failure modes
Teams evaluate conversion with text-level and structure-level metrics: character or word error rate for content, edit distance against reference Markdown, and table-structure scores such as TEDS for tables. A sample of manually reviewed pages from the real document mix remains essential, since public benchmarks rarely match a company’s own files.
The table below lists the failures practitioners encounter most often and how to address them.
| Failure | Typical cause | Remedy |
|---|---|---|
| Interleaved sentences | Wrong reading order on multi-column pages | Use a layout model with column detection |
| Repeated headers on every chunk | Page furniture not removed | Filter running headers and footers |
| Garbled characters | Broken font encoding in the PDF | Fall back to OCR for affected pages |
| Invented or missing sentences | Hallucination in generative models | Compare against OCR text, flag low-confidence pages |
| Shifted table columns | Merged cells or missing ruling lines | Use a table-structure model or HTML output |
A key warning applies to end-to-end models: their output can be fluent but unfaithful, for example repeating a line or completing a truncated sentence. For legal, medical or financial content, conversion should include automated consistency checks and human review of uncertain pages.
In plain words
A PDF is like a printed page. It knows where each letter sits, but not what the letters mean together. Document-to-Markdown conversion rebuilds the meaning. It finds the titles, the paragraphs, the lists and the tables.
The result is a simple text file with light marks, such as a hash sign before a title. People can read it easily. AI tools can read it even better. Good conversion means the AI sees the document the way a person does, in the right order and with tables intact.
A real-world example
An insurance company wants an internal assistant that answers adjusters’ questions about roughly 8,000 policy documents. The first prototype uses plain text extraction, and answers are often wrong, because coverage tables lose their columns and two-column clauses are read across the page.
The team switches to a modular conversion pipeline with layout detection, OCR for older scanned policies and a table-structure model. Each document becomes Markdown with proper headings, and chunks are split at section boundaries with the section path attached. Pages with low OCR confidence are flagged for manual review, which affects roughly 3 percent of pages.
In a review of 200 test questions, the share of answers judged correct rises noticeably, and adjusters report that cited passages now match the original policy wording. The company also saves tokens, because Markdown chunks are shorter than the earlier JSON layout output.