Guide · Docling

Docling PDF to Markdown: CLI and Python workflow

Docling parses PDFs and other documents into a structured DoclingDocument, then exports Markdown, HTML or JSON. It is a practical choice when you need layout understanding and a Python API rather than a one-off web converter.

Updated November 23, 2026 · Markdown2PDF by Hyperdyn

What Docling adds to PDF extraction

Docling combines layout analysis, reading-order detection, table structure and optional OCR. It can export the result as Markdown, HTML, JSON, text and other formats. It also supports DOCX, PPTX, HTML and several other inputs, which makes it useful for a mixed document collection.

The project is developed under the Docling name by IBM Research and is now part of the LF AI & Data Foundation. It runs locally, so confidential PDFs do not have to be uploaded to a third-party service.

Install Docling

Docling requires Python 3.10 or newer. Create a virtual environment and install the package:

python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS / Linux: source .venv/bin/activate
pip install docling

The first conversion may download models. That is expected; later runs reuse the cached model files. Check the current Docling installation guide if you need a specific OCR engine, GPU backend or offline model layout.

Convert PDF to Markdown with the Docling CLI

The current CLI uses the convert subcommand. This writes Markdown into an output directory:

docling convert input.pdf --to md --output output

The shorthand docling input.pdf also produces Markdown in the current directory according to the project README. For repeatable jobs, use the explicit convert, --to md and --output form.

You can request more than one output format in the same run, for example --to md --to json. Use docling convert --help for the options supported by the installed version.

Use Docling from Python

The Python API gives you the parsed document object, so you can inspect it before exporting:

from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("input.pdf")
markdown = result.document.export_to_markdown()

with open("output.md", "w", encoding="utf-8") as handle:
    handle.write(markdown)

This is the simplest pipeline. For production work, keep the converter reuseable and add error handling around corrupt, encrypted or unusually large PDFs.

What to check in the converted Markdown

  • Reading order: multi-column pages and sidebars are the first place layout analysis can go wrong.
  • Tables: verify headers, merged cells and numeric alignment.
  • Scans: if the PDF has no text layer, confirm that OCR was enabled and that the language was detected correctly.
  • Images and formulas: confirm that the exported Markdown points to files that actually exist and that equations are still readable.

Do not compare only the first page. A converter can look perfect on a title page and fail on a dense table ten pages later.

Docling or another PDF converter?

Choose Docling when you want a structured document model and a Python-first workflow. Marker is another strong option for layout-heavy PDFs and has CPU, GPU and LLM-assisted modes. MarkItDown is lighter and oriented toward LLM input. A plain text extractor is enough when you do not need Markdown structure.

The full PDF to Markdown comparison covers the wider tool landscape. If your next step is a finished document rather than a Markdown file, use the Markdown to PDF converter.

Frequently asked questions

Does Docling work with scanned PDFs?

Docling supports OCR, but scanned documents need the OCR pipeline and suitable language data. Scan quality, rotation and handwriting all affect accuracy, so review the Markdown before relying on it.

What is the Docling CLI command for Markdown?

The current form is docling convert input.pdf --to md --output output. The exact options can change between releases, so check docling convert --help for your installed version.

Is Docling free to use?

The Docling codebase is released under the MIT license. Individual models may have their own licenses, so check the model documentation if you plan to use it commercially.