Practical Docling Examples

Short, task-oriented recipes with a CLI command, Python equivalent, the flags used, expected output and the common mistake to avoid. Every recipe links to the official source.

PDF to Markdown

PDF & conversion

Clean, readable Markdown from any digital PDF.

When to use: Use when you need clean, readable Markdown from a digital or mixed PDF.

CLI

docling convert report.pdf --to md

Python

from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("report.pdf")
print(result.document.export_to_markdown())

Flags used

  • --to md Selects Markdown output.

Expected output

# Annual Report

## Revenue

| Year | Revenue |
|---|---:|
| 2025 | $12M |
| 2026 | $15M |

Variations

Skip OCR for speed

docling convert report.pdf --to md --no-ocr

Common mistake: Running on a scanned PDF and getting empty text. If the PDF has no text layer, use OCR (--ocr-mode full_page).

Official docs → · PDF to JSON →

PDF to JSON

PDF & conversion

The full DoclingDocument structure for custom pipelines.

When to use: Use when you need the lossless DoclingDocument structure, including bounding boxes and layout metadata.

CLI

docling convert report.pdf --to json

Python

import json
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("report.pdf")
print(json.dumps(result.document.export_to_dict(), indent=2))

Flags used

  • --to json Exports the lossless JSON representation.

Expected output

{
  "schema_name": "DoclingDocument",
  "texts": [ ... ],
  "tables": [ ... ]
}

Variations

Skip OCR for speed

docling convert report.pdf --to json --no-ocr

Common mistake: Expecting the CLI JSON and export_to_dict() to be byte-identical; they are equivalent representations of the same document.

Official docs → · PDF to Markdown →

URL to Markdown

PDF & conversion

Convert a document straight from an HTTP URL.

When to use: Use when the document is hosted online and you do not want to download it first.

CLI

docling convert https://arxiv.org/pdf/2408.09869 --to md

Python

from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("https://arxiv.org/pdf/2408.09869")
print(result.document.export_to_markdown())

Expected output

## Docling Technical Report

...

Variations

Export JSON instead

docling convert https://arxiv.org/pdf/2408.09869 --to json

Common mistake: Assuming any URL works. The source must be a supported document format reachable over HTTP.

Official docs → · Supported formats →

Scanned PDF with OCR

OCR & scans

Recover text from image-only pages.

When to use: Use when pages are images and contain no selectable text.

CLI

docling convert scan.pdf --ocr-mode full_page

Python

from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
)
result = converter.convert("scan.pdf")
print(result.document.export_to_markdown())

Flags used

  • --ocr-mode full_page Runs OCR on every page, even those that already contain text.

Expected output

Text reconstructed from the scanned page image.

Variations

Choose a different engine

docling convert scan.pdf --ocr-mode full_page --ocr-engine rapidocr

Common mistake: Leaving OCR on for digital PDFs wastes time. Only enable it when the text layer is missing.

Official docs → · Compare OCR engines →

Disable OCR for digital PDFs

OCR & scans

Dramatically faster conversion for digital PDFs.

When to use: Use when the PDF already contains a text layer and you want the fastest conversion.

CLI

docling convert report.pdf --no-ocr --to md

Python

from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = False

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
)
result = converter.convert("report.pdf")
print(result.document.export_to_markdown())

Flags used

  • --no-ocr Skips the OCR stage entirely.

Expected output

Markdown produced without running OCR.

Variations

Fast tables as well

docling convert report.pdf --no-ocr --table-mode fast

Common mistake: Disabling OCR on a scanned PDF results in little or no text.

Official docs → · All commands →

Extract tables

Tables

Turn tables into Markdown or HTML matrices.

When to use: Use when the document contains tables you want as Markdown or HTML matrices.

CLI

docling convert report.pdf --to md

Python

from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

pipeline_options = PdfPipelineOptions()
pipeline_options.do_table_structure = True

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
)
result = converter.convert("report.pdf")
print(result.document.export_to_markdown())

Flags used

  • --table-mode accurate Uses TableFormer for complex, merged-cell tables.

Expected output

| Region | Q1 | Q2 |
|---|---:|---:|
| EMEA | 4.2 | 4.8 |

Variations

Faster, approximate tables

docling convert report.pdf --to md --table-mode fast

Common mistake: Assuming every table is perfect. Merged cells and borderless tables can still need review; try --table-mode accurate.

Official docs → · Build a custom command →

Extract formulas and code

Formulas & code

Capture equations and code blocks as LaTeX.

When to use: Use for scientific or technical documents containing equations or code blocks.

CLI

docling convert paper.pdf --enrich-code --enrich-formula

Python

from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

pipeline_options = PdfPipelineOptions()
pipeline_options.do_code_enrichment = True
pipeline_options.do_formula_enrichment = True

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
)
result = converter.convert("paper.pdf")
print(result.document.export_to_markdown())

Flags used

  • --enrich-code Detects code blocks.
  • --enrich-formula Extracts LaTeX formulas.

Expected output

$$ E = mc^2 $$

Variations

Add chart extraction

docling convert paper.pdf --enrich-code --enrich-formula --enrich-chart-extraction

Common mistake: Enabling enrichment on documents without formulas or code adds processing time for little benefit.

Official docs → · Build a custom command →

RAG chunking with HybridChunker

RAG

Structure-aware chunks ready for a vector store.

When to use: Use when you want chunks that preserve headings, tables and page metadata for a vector store.

CLI

docling convert report.pdf --to chunks --chunks-type hybrid

Python

from docling.document_converter import DocumentConverter
from docling.chunking import HybridChunker

converter = DocumentConverter()
result = converter.convert("report.pdf")

chunker = HybridChunker()
for chunk in chunker.chunk(result.document):
    print(chunk.text)

Flags used

  • --to chunks Emits chunked output.
  • --chunks-type hybrid Uses HybridChunker.

Expected output

Chunks split on document structure rather than raw character counts.

Variations

Inspect the raw export

docling convert report.pdf --to json

Common mistake: Using a naive character splitter instead of structure-aware chunking, which breaks tables and headings.

Official docs → · RAG guide →

LangChain integration

Integrations

Load parsed documents into a LangChain pipeline.

When to use: Use when loading parsed documents into a LangChain pipeline.

CLI

pip install langchain-docling

Python

from langchain_docling import DoclingLoader

loader = DoclingLoader(file_path="report.pdf")
docs = loader.load()
print(docs[0].page_content[:200])

Expected output

LangChain Document objects with parsed page content and metadata.

Variations

Then convert a file

docling convert report.pdf --to md

Common mistake: Forgetting to install the integration package separately from docling.

Official docs → · LlamaIndex recipe →

LlamaIndex integration

Integrations

Build LlamaIndex nodes from parsed files.

When to use: Use when building LlamaIndex document nodes from parsed files.

CLI

pip install llama-index-readers-docling

Python

from llama_index.readers.docling import DoclingReader

reader = DoclingReader()
documents = reader.load_data(file_path="report.pdf")
print(documents[0].text[:200])

Expected output

LlamaIndex documents ready for indexing.

Variations

Then convert a file

docling convert report.pdf --to md

Common mistake: Mixing versions of docling and the reader package; keep both current.

Official docs → · LangChain recipe →

Verified with Docling v2.129.0 · Last checked 2026-09-22 · Official source

1
Start here

How to use these examples

Ten copy-ready recipes for the most common Docling jobs. Each one includes a CLI command, the Python equivalent, the flags it uses, the expected output and the mistake to avoid.

Work through a recipe from top to bottom.

  1. Find your task. Filter by category or search for a flag or keyword.
  2. Copy the command. Use the Copy button on the CLI block, or copy the Python equivalent.
  3. Run it. Commands write the converted file next to the source by default.
  4. Check the output. Compare it against the expected output shown in the recipe.
  5. Adapt it. Add flags from the recipe or build a custom command in the config generator.
2
Setup

Before you start

Every example assumes Docling is installed and you have a sample document ready.

  • Python 3.10 or newer is required.
  • OCR examples need an OCR engine; RapidOCR is a good CPU default.
  • The integration examples install a separate package.
pip install docling
docling --help
3
Choose

Which example should I use?

I want to…ExampleKey option
Get readable textPDF to Markdown--to md
Get structured dataPDF to JSON--to json
Convert a URLURL to MarkdownURL argument
Read a scan or photoScanned PDF with OCR--ocr-mode full_page
Speed up digital PDFsDisable OCR--no-ocr
Extract tablesExtract tables--table-mode
Get formulas and codeExtract formulas and code--enrich-*
Chunk for RAGRAG chunking--to chunks
Use LangChainLangChain integrationintegration package
Use LlamaIndexLlamaIndex integrationintegration package
4
Adapt

How to adapt a recipe

  • Change the file name or URL to point at your own source.
  • Add --no-ocr for digital PDFs and --ocr-mode full_page for scans.
  • Switch the output with --to md, --to json, --to html or --to doctags.
  • Add --device cuda and --num-threads for large batches.
  • Build the full command in the config generator.
5
CLI vs Python

CLI or Python?

Use the CLI for one-off conversions and the Python API when you need to post-process the document, batch many files or integrate with another library.

  • CLI: quick, scriptable and needs no code.
  • Python: full access to DoclingDocument, chunks and pipeline options.
6
Next

Keep exploring

7
FAQ

Frequently asked questions

Do these examples work as-is?
Yes, once Docling is installed. Replace the sample file name (report.pdf, scan.pdf, paper.pdf) with your own.
Where does the converted file go?
Next to the source file by default, with an extension that matches the output format.
Can I run several files at once?
Yes. Pass multiple paths to the CLI, or loop over files in Python.
How do I choose between CLI and Python?
Use the CLI for quick conversions and Python when you need to process the result programmatically.
Why is my scanned PDF empty?
It has no text layer. Use the scanned-OCR recipe with --ocr-mode full_page.
How do I get chunks for a vector database?
Use the RAG chunking recipe, then feed the chunks to your vector store. See the RAG guide.