Recipe · PDF → Markdown
Docling PDF to Markdown: One Command, Then the Hard Part
Docling's default output is Markdown, so the conversion is the easy part. The work is knowing what survived: headings and reading order come through well; table geometry and figures do not. That distinction decides whether Markdown is the right format for your task.
Updated 2026-10-26 · 3 min read
The short version
- –CLI:
docling convert file.pdf --to md. Python:doc.save_as_markdown()/export_to_markdown(). Markdown is the default format. - –Docling reconstructs reading order and heading hierarchy before writing Markdown — that is the reason its output is usable where a plain text extractor's is not.
- –Markdown tables are a rendering of a table, not a data structure: merged cells flatten, and a table split across pages returns as separate tables.
- –If the destination is a spreadsheet, do not go through Markdown — see Docling to Excel.
- –Emit
--to jsonalongside Markdown when you may need the structure later. Converting twice is more expensive than storing both.
The command
from docling.document_converter import DocumentConverter
doc = DocumentConverter().convert("report.pdf").document
markdown = doc.export_to_markdown()
with open("report.md", "w", encoding="utf-8") as f:
f.write(markdown)
# or let Docling name and write the file
doc.save_as_markdown("report.md")What Markdown keeps
- Reading order. The single most valuable thing: two-column layouts, sidebars and footnote blocks arrive in the order a human reads them.
- Heading hierarchy. Section levels become
#–######, which is what makes the output navigable and chunkable. - Lists and structure. Bulleted and numbered lists keep their shape instead of collapsing into sentences.
- Tables, in Markdown form. Rows and columns survive as pipe tables — good for reading, limited for computing.
- Formulas when the pipeline enriches them, typically as LaTeX.
- Page-level fidelity to the source in the accompanying JSON, even though Markdown itself carries no page numbers.
What Markdown loses
This is not a Docling defect; it is what Markdown is. The format has no concept of a cell span, an image region or a page. Anything you need beyond text order has to come from the JSON.
| Need | Markdown output | Where to get it |
|---|---|---|
| Merged cells / spans | Flattened into one column | --to json (table cell spans) |
| Two-row headers | Collapsed | --to json |
| Page numbers per paragraph | Absent | JSON provenance |
| Figures and images | Text placeholder or reference, not pixels | Image export mode / JSON refs |
| Numbers as numbers | Text | JSON or a data frame (Excel path) |
| Confidence / uncertainty | Absent | Not exported — verify against the page |
Picking the right target format
- Markdown — reading, publishing, feeding a RAG pipeline, diffing versions in git.
- JSON (DoclingDocument) — anything that needs structure: cells, provenance, page references, custom rendering.
- DocTags — token-level representation for custom parsers and model input.
- HTML — when a browser will render it and tables should stay tables.
- LaTeX — formula-heavy output for scientific writing.
- XLSX/CSV — not a Docling export; see the Docling to Excel guide for the two working routes.
A practical default for anything archival: emit both --to md and --to json. The Markdown is for humans and search; the JSON is what lets you answer questions later without re-parsing.
Markdown for RAG: the part that matters
Docling became popular for retrieval because reading order is the thing naive extractors get wrong, and a chunk with scrambled order retrieves badly no matter how good the embedding model is.
But chunking the Markdown afterwards throws away what you paid for: heading paths, table identity and page numbers live in the document model, not in the text file. Chunk from the document (--to chunks) if the downstream task is retrieval — see chunking for RAG.
Common output problems
- Empty or near-empty .md from a scan — OCR was disabled or no engine is installed. See Docling OCR.
- Tables as paragraphs — the table region was not detected; try the accurate table mode and better input resolution.
- Interleaved columns — a layout the reading-order model misread; the VLM pipeline sometimes handles these pages better.
- Missing images — Markdown references assets rather than embedding them by default; choose an image mode that matches where you will render the file.
- Formulas as plain text — formula enrichment did not run; check the pipeline options for your version.
Try Without Local Installation
The conversion itself is one command, but setting up the local environment requires Python, PyTorch, and multi-gigabyte models. If you want to evaluate PDF to Markdown extraction immediately without installation, test it directly on doclingocr.com Online Web GUI.
For a folder of papers, use the local Docling CLI and keep the original file name alongside each Markdown export. The browser viewer handles one PDF at a time and exports its text layer as JSON.
Frequently asked questions
How do I convert a PDF to Markdown with Docling?+
Run docling convert file.pdf (Markdown is the default), or docling convert file.pdf --to md --output ./out. In Python, DocumentConverter().convert(path).document.export_to_markdown().
Does Docling preserve tables in Markdown?+
It emits Markdown pipe tables, so rows and columns are readable. Merged cells and multi-row headers flatten because Markdown cannot represent them — use --to json if you need the cell structure.
Can I get page numbers in the Markdown?+
Not in the Markdown itself. Page provenance is in the DoclingDocument (and therefore the JSON output), which is why emitting both formats is a sensible default.
Is Markdown the best output for RAG?+
Markdown is fine if you will chunk it yourself, but chunking from the document model preserves headings, table identity and page numbers. Use --to chunks when retrieval is the goal.
How do I convert many PDFs to Markdown at once?+
Pass a folder or loop in Python over your files, writing one .md per document. Keep a manifest mapping output files to source hashes so re-runs are idempotent.
Try it online
Run the same pipeline in the browser — no install, no uploads stored.
See the recorded run →Keep reading
- Papers to Markdown
Double-column layouts and formulas
- Chunking for RAG
Structure-aware chunks
- Docling to Excel
When a spreadsheet is the target
- CLI reference
--to md and other formats
- Python API
export_to_markdown in context
- Into Obsidian & Notion
Where the Markdown goes next