Docling PDF to Markdown: a local-file example

Convert a PDF with the Python API, save UTF-8 Markdown, and check headings, table cells, and reading order.

For
People working with document data
Reading time
4 min

Start here

  1. Install Docling in a separate Python environment.
  2. Convert a local file and write the Markdown result.
  3. Compare the output with a few known source values.

Downloads

Install in a separate environment

Use Docling’s current installation guide for the supported Python version and platform. Keep this environment separate from an unrelated application. The first conversion may download model assets; local input does not mean a fresh installation can run without any network setup.

Terminal · documentation-based example
python -m venv .venv
# Activate the environment using your platform’s command.
python -m pip install docling

Save a Markdown file

The official quickstart exposes DocumentConverter and export_to_markdown. This adapted example takes sample.pdf from the current folder and writes output.md. Use an output directory that does not contain your only copy of the source.

Python · save as convert_pdf.py
from pathlib import Path
from docling.document_converter import DocumentConverter

source = Path("sample.pdf")
result = DocumentConverter().convert(source)
Path("output.md").write_text(
    result.document.export_to_markdown(), encoding="utf-8"
)

This is a documentation-based example, not a measured conversion benchmark. Check the installed version before adapting it to a batch job.

Use a small known input

The downloadable fixture has a heading, a three-row product table, and codes with leading zeros. Open the HTML fixture and print it to PDF as sample.pdf. Compare your output to the human-written reference Markdown. The reference describes the intended content; it is not output generated or verified by Docling.

FieldExpected check
SKU 00123Leading zeros remain
Unit price 12.50Decimal value remains correct
Pack quantity 6Does not become part of the unit price
Paragraph after the tableAppears after the table in reading order

Handle scans and images separately

A PDF can contain text, page images, or both. OCR settings and the environment affect a scan conversion. Also check how images are exported before assuming the Markdown file is a self-contained archive. Keep images alongside the text when downstream readers need them.

Record a useful result

Write down package version, input type, failed cells, and runtime on your own machine. Review continued tables and multi-column pages before expanding to a folder. If you only need a few text-based tables, the Tabula comparison may lead to a simpler workflow.

Sources

Updated October 30, 2026. Based on the linked documentation; the tools have not been benchmarked by NarrowTools. Editorial policy

Read next

Marker PDF to Markdown: convert one file firstUse Marker’s documented single-file command, check current inference requirements, and compare the result with a known sample.Tabula alternatives: when to use Docling for PDF tablesUse Tabula for a supervised extraction, or Docling as part of a document pipeline. Compare them on the same difficult pages.