# Docling: Convert PDFs to Markdown and JSON with Python

> Learn what Docling does, how to convert a PDF to Markdown and JSON with Docling in Python, and when a managed parsing API is a better fit for production.

Canonical: https://reducto.ai/guides/docling

## What is Docling?

[Docling](https://docling-project.github.io/docling/) is an open-source, MIT-licensed Python toolkit that converts documents into a structured representation called a `DoclingDocument`, then exports it to Markdown, HTML, lossless JSON and other formats. It handles PDFs, Office files, HTML, images and many other inputs, and it runs on your own hardware.

The short answer for most searchers: install it with `pip install docling`, pass a file path or URL to `DocumentConverter`, and call `export_to_markdown()` or `save_as_json()` on the result. The rest of this guide shows that workflow on a real, synthetic PDF, explains what the JSON contains, and covers the deployment decisions that come after the first conversion.

## What Docling does

Docling is more than an OCR wrapper. According to its [documentation](https://docling-project.github.io/docling/), its PDF pipeline understands page layout, reading order, table structure, code, formulas and image classification. The output keeps that structure: headings stay headings, tables keep their rows, columns and header cells, and each element records the page and bounding box it came from.

Other capabilities documented by the project include:

- [Input formats](https://docling-project.github.io/docling/usage/supported_formats/) such as PDF, DOCX, XLSX, PPTX, HTML, EPUB, LaTeX, email and common image types.
- Several OCR engines for scanned pages, including EasyOCR, Tesseract and RapidOCR, installed as [optional extras](https://docling-project.github.io/docling/getting_started/installation/).
- Optional vision-language model pipelines, such as GraniteDocling.
- Chunking for retrieval, plus integrations with LangChain, LlamaIndex, Crew AI and Haystack.
- A command-line interface, an MCP server and an API server called docling-serve.

Docling therefore already produces layout-aware, structured output. The real question for a team is less "can it convert this PDF?" and more "do we want to run the conversion service ourselves?"

## Install Docling and convert a PDF

The example below uses Docling 2.152.0 on Python 3.12 in a fresh virtual environment on a CPU-only Linux machine. The [installation guide](https://docling-project.github.io/docling/getting_started/installation/) recommends the PyTorch CPU index for that setup; on other machines, `pip install docling` is enough.

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install "docling==2.152.0" --extra-index-url https://download.pytorch.org/whl/cpu
```

The input is a one-page synthetic invoice we generated for this guide. It has a title, a vendor line, a section heading, a four-row table and a payment note. No customer data is involved.

The conversion script follows the official [Docling quickstart](https://docling-project.github.io/docling/getting_started/quickstart/), with a local file instead of a URL:

```python
from docling.document_converter import DocumentConverter

source = "synthetic_invoice.pdf"  # file path or URL
converter = DocumentConverter()
doc = converter.convert(source).document

print(doc.export_to_markdown())
doc.save_as_json("synthetic_invoice.json")
```

On the first run, Docling downloads its layout and table models, so the first conversion is slower than later ones.

## Export Markdown and JSON

### Docling PDF to Markdown

The real Markdown output for the synthetic invoice:

```markdown
## Invoice INV-1001

Northwind Supply Co. (synthetic sample)

## Line items

| Item     |   Qty | Unit price   | Amount   |
|----------|-------|--------------|----------|
| Widget A |    10 | $4.00        | $40.00   |
| Widget B |     3 | $12.50       | $37.50   |
| Total    |       |              | $77.50   |

Payment is due within 30 days.
```

The heading levels, reading order and table survived as Markdown that can be passed straight to an LLM or a chunker.

### Docling JSON

`save_as_json()` writes the full `DoclingDocument`. In our run, the file reported `"schema_name": "DoclingDocument"` and version `1.12.0`, with top-level keys such as `body`, `texts`, `tables`, `pictures` and `pages`. A trimmed excerpt of the first text item:

```json
{
  "self_ref": "#/texts/0",
  "label": "section_header",
  "text": "Invoice INV-1001",
  "prov": [
    {
      "page_no": 1,
      "bbox": {"l": 234.468, "t": 708.924, "r": 377.532, "b": 692.274, "coord_origin": "BOTTOMLEFT"},
      "charspan": [0, 16]
    }
  ]
}
```

Table cells are stored individually, with row and column offsets, spans, a `column_header` flag and their own bounding boxes. This is the format to keep if you need provenance, want to rebuild tables in code or plan to re-export later. Markdown is a lossy view of the same document.

### Using the Docling CLI

The same conversion runs from the terminal. This command, run with the same version, wrote both `synthetic_invoice.md` and `synthetic_invoice.json` to `out/`:

```bash
docling synthetic_invoice.pdf --to md --to json --output out
```

`docling --help` lists the other options, including OCR engine choice, pipeline selection and chunked output.

## Local operation and deployment decisions

Running Docling locally is its main draw for sensitive documents. Models download on first use, and the [advanced options](https://docling-project.github.io/docling/usage/advanced_options/) page shows how to prefetch them with `docling-tools models download` for air-gapped environments. After the first prototype, a production pipeline usually needs decisions on:

- **Hardware.** Docling depends on PyTorch. Pick CPU or GPU builds, and size memory for your largest documents.
- **OCR engine.** Scanned pages need an OCR engine, and each engine has its own install steps, languages and quality tradeoffs.
- **Service shape.** Choose between in-process conversion, batch jobs, or docling-serve behind your own queue and authentication.
- **Version pinning.** Pin Docling and its model versions, and keep a regression set so output changes are caught before an upgrade ships.
- **Monitoring and review.** Track failed pages, timeouts and documents that need a person to check them.

None of this is a flaw in Docling. It is the normal work of running any self-hosted document pipeline.

## When to consider a managed parsing API

A managed API makes sense when you would rather call an endpoint than run conversion infrastructure, or when your documents are hard enough that you want a dedicated parsing service. [Reducto Parse](https://reducto.ai/parse) reads every page and returns text, tables, figures, layout and formatting with bounding boxes, organized into chunks for LLMs, RAG pipelines or downstream extraction. See the [Parse overview](https://docs.reducto.ai/parse/overview) for details. It runs on [r-1](https://docs.reducto.ai/parse/r-1), Reducto's full-page parsing model.

<Table html={"<table>\n  <thead>\n    <tr>\n      <th>Question</th>\n      <th>Docling, self-operated</th>\n      <th>Reducto Parse</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Where it runs</td>\n      <td>Your machines, including air-gapped hosts after model prefetch</td>\n      <td>Reducto's hosted API, Hybrid VPC or full VPC</td>\n    </tr>\n    <tr>\n      <td>Output</td>\n      <td>DoclingDocument exported to Markdown, HTML, lossless JSON and more</td>\n      <td>Chunks with text, tables, figures, layout and bounding boxes</td>\n    </tr>\n    <tr>\n      <td>Who operates it</td>\n      <td>Your team handles packaging, models, hardware, scaling and upgrades</td>\n      <td>Reducto runs the parsing service; you call an API</td>\n    </tr>\n    <tr>\n      <td>Main ongoing work</td>\n      <td>Capacity planning, queueing, monitoring and regression tests</td>\n      <td>Pipeline and review design for your documents</td>\n    </tr>\n  </tbody>\n</table>"} />

Reducto's deployment options include the hosted API, Hybrid VPC and full VPC, so teams that chose Docling for data control can still keep processing inside their own cloud. Parse also feeds Reducto's extraction, splitting and classification tools when a workflow needs structured fields as well as parsed content.

Test both options on the same set of your own files. Check reading order, table structure, scanned pages and the time your team spends keeping the pipeline running. For broader comparisons, see our guides to the [best document parsers for RAG](https://reducto.ai/guides/best-document-parsers-rag) and [PDF OCR software for AI workflows](https://reducto.ai/guides/best-pdf-ocr-software-ai-workflows). To try Reducto on your own documents, start in [Reducto Studio](https://studio.reducto.ai).

## Frequently asked questions

### Is Docling free?

Yes. Docling is open source under the MIT license. Your costs are the compute, storage and engineering time needed to run it.

### Does Docling work on scanned PDFs?

Yes. Docling supports several OCR engines for scanned PDFs and images. Install the engine you want as an extra or a system dependency, then select it in the pipeline options.

### Should I keep Docling Markdown or JSON?

Keep the JSON as the source of record because it preserves labels, page numbers, bounding boxes and table cells. Generate Markdown from it when you need LLM-friendly text or chunks.

### Can Docling run without internet access?

Yes. Prefetch the models with `docling-tools models download`, then point Docling at the local model directory.

### When is Reducto a better fit than Docling?

Reducto is worth testing when you want a managed parsing API instead of operating conversion infrastructure, or when complex tables, scans and irregular layouts make parsing quality the main risk.
