Docling Puts the Structure Back into PDFs Before RAG Ever Retrieves
Why More and More People Use Docling
Preface
Have you ever hit this situation: you spend most of a day feeding a PDF into a RAG system, and the retrieved snippets come back as broken tables and misaligned headings. The large model takes those fragments and seriously makes up answers for you.
You figure the Embedding model is to blame, so you switch it.
You figure the chunk size is wrong, so you adjust it.
You figure the vector database retrieval strategy is off, so you change that too.
After all that effort, the results are still the same.
The problem isn't at the retrieval layer. It's further upstream.
The "raw material" you feed in loses its structure the moment it changes from PDF to text.
And Docling exists specifically to solve this.
Made by IBM Research, donated to the Linux Foundation in March 2025, and became a Graduated project of the LF AI & Data Foundation in August 2026.
GitHub stars exceed 70,000, and more than 68% of community PRs come from outside the core team.
This article talks with everyone about Docling, hoping it will be helpful.
More project practice at Java Commando Team: susan.net.cn/project
1. What problem does Docling solve?
Some people might say: "Aren't there plenty of PDF parsing tools? Can't PyMuPDF and pdfplumber do the job?"
They can.
But they solve the problem of "digging the characters out."
Docling solves the problem of "keeping the structure."
A PDF is essentially a pile of "instructions drawn on the page."
It tells you "draw this text at coordinates (x, y)" but not "whether this text is a heading or body text," "how many rows and columns this table has," or "whether these two columns should be read left first or right first."
Traditional tools dig the characters out, and the structure is lost.
You get "a pile of text," not "a document."
What Docling does is use AI models to "restore" a PDF's visual information into logical structure. It recognizes headings, paragraphs, tables, images, formulas, and code blocks, then reorganizes them in human reading order, outputting a DoclingDocument object with hierarchy, position information, and table structure.
In one sentence: Docling upgrades "can be read" into "can be used structurally."
2. A diagram to understand Docling's overall pipeline
Docling's architecture is modular, with each layer having clear responsibilities:
Parsing backend: different parsers for different formats. PDF uses the self-developed docling-parse, built on qpdf, solving PyMuPDF's license restrictions and pypdfium's quality problems.
AI processing pipeline: StandardPdfPipeline runs OCR, layout analysis, and table structure recognition in parallel. Layout analysis uses the DocLayNet model, table recognition uses TableFormer.
Unified document model: all formats ultimately become a DoclingDocument with hierarchy, position, and table structure. You can export lossless JSON, or export Markdown or HTML.
3. Underlying principles
This section covers the three most core aspects of Docling. I'll try to make the "input" and "output" of each stage clear with diagrams.
3.1 Layout analysis: first figure out "what is where"
Traditional tools take a PDF and start digging characters out directly. Docling takes a PDF and first renders each page into an image, then runs the layout analysis model.
The goal of this step isn't to "recognize characters," it's to "recognize elements."
The DocLayNet model identifies which type each element on the page belongs to: heading, paragraph, table, image, formula, code block, plus its coordinate position on the page.
The value of this step: everything after it processes based on "elements" rather than a "text stream."
It knows "this is a table," so it uses the table recognition model; it knows "this is a heading," so it preserves the hierarchy.
3.2 Reading order restoration: multi-column layouts no longer get scrambled
Layout analysis tells you "what is where"; reading order restoration tells you "what to read first, what to read next."
The reading order of a two-column paper is "left column top to bottom, then right column top to bottom."
But PDFs have no concept of "columns," only coordinates. If you hard-sort by coordinates top to bottom, left to right, the bottom of the left column and the top of the right column get joined together, and the context breaks.
Docling's reading order model infers how a human would read the page based on element positions and types.
Left: the result of "hard-sorting by coordinates": paragraph 1 is followed directly by paragraph 3; the context is broken.
Right: the order Docling restores: the left column is finished before the right column starts; the logic is coherent.
3.3 Table structure recognition: TableFormer turns "a pile of numbers" back into "a table"
This is Docling's most underrated capability.
Traditional tools extracting tables either break the table into scattered text blocks or use simple row/column cuts, which collapse on merged cells. What you get is "a pile of numbers," not "a table with structure."
The TableFormer model predicts the table's row and column structure, including merged cells, multi-level headers, and lists embedded in cells. Its output isn't text; it's a structured table with row-column relationships.
What does this mean?
When the RAG system retrieves this table, the large model can understand "which metric and which column this number belongs to."
Instead of receiving scattered numbers and having to guess on its own.
4. Code in practice: from PDF to RAG-ready chunks
4.1 Installation
pip install docling
Python 3.10 or above.
macOS, Linux, and Windows are all supported.
4.2 Basic conversion: PDF to Markdown
from docling.document_converter import DocumentConverter
source = "your_document.pdf"
converter = DocumentConverter()
result = converter.convert(source)
print(result.document.export_to_markdown())
4.3 Handling scanned documents: enable OCR
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.datamodel.base_models import InputFormat
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.do_table_structure = True
converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
}
)
doc = converter.convert("scanned_invoice.pdf").document
print(doc.export_to_markdown())
4.4 RAG chunking: HybridChunker feeds structure into the vector database
This is the most critical step for combining Docling with RAG.
Plain character chunking cuts sentences and breaks tables apart. HybridChunker chunks according to the document's structure: paragraphs under a heading aren't split, and tables aren't cut in half. It also uses tokenizer-aware methods to make sure chunk sizes fit your Embedding model.
from docling.document_converter import DocumentConverter
from docling.chunking import HybridChunker
converter = DocumentConverter()
doc = converter.convert("employee_handbook.pdf").document
chunker = HybridChunker()
chunks = list(chunker.chunk(dl_doc=doc))
for chunk in chunks[:3]:
# contextualize() merges metadata like section headings back into the chunk text
print(chunker.contextualize(chunk))
print("---")
The value of contextualize(): a chunk about "resignation policy" might originally be just one sentence, "Resignation requires 30 days' notice." contextualize() merges in the hierarchy "Employee Handbook > HR Policy > Resignation Management." The Embedding model receives text with context, and retrieval accuracy naturally improves.
5. Pros and cons
Pros
1. Structured output, RAG-friendly
Output is a DoclingDocument with hierarchy, table structure, and position information, not "a pile of text." Combined with HybridChunker, chunk quality far exceeds character chunking.
2. Strong table recognition
The TableFormer model restores row-column structure, merged cells, and multi-level headers. TEDS scores range from 0.877 to 0.911.
3. Runs fully locally
Models download to local machines and inference runs locally. Sensitive-data and offline intranet scenarios work too.
4. Unified multi-format
PDF, DOCX, PPTX, XLSX, HTML, Markdown, images, and audio all go through the same DoclingDocument model.
5. Mature ecosystem integration
Native support for LangChain and LlamaIndex, an MCP Server, and a docling-java wrapper for Java.
6. Reliable open-source governance
Linux Foundation Graduated project, contributors from 109 organizations, high community activity.
Cons
1. Not the fastest
Processing a complex PDF on CPU takes about 9 to 10 seconds. Marker or PyMuPDF4LLM are faster on simple PDFs.
2. Complex tables still have limits
For deeply nested tables, commercial solutions like Reducto claim about 20% higher accuracy.
3. Python ecosystem, Java needs a workaround
Docling itself is a Python package. Java projects must call it through the docling-serve REST API or the docling-java wrapper, adding a layer of network overhead.
4. Some advanced features are off by default
Formula-to-LaTeX, code block recognition, and image description are off by default and require manual enabling.
6. Use cases
| Scenario | Recommendation | Reason |
|---|---|---|
| RAG knowledge base document preprocessing | ✅✅✅ Strongly recommended | Structured output + HybridChunker, high chunk quality |
| Need to preserve table structure | ✅✅✅ Strongly recommended | TableFormer restores rows, columns, and merged cells |
| Sensitive data, cannot go to cloud | ✅✅✅ Strongly recommended | Runs fully locally, usable offline |
| Technical docs / academic papers | ✅✅✅ Strongly recommended | Strong layout analysis and reading order restoration |
| Pursuing extreme parsing speed | ⚠️ Evaluate | Slower than Marker on CPU |
| Extremely complex nested tables | ⚠️ Evaluate | Commercial solutions still hold an edge |
| Pure Java tech stack | ⚠️ Evaluate | Requires calling through REST API |
7. In closing
Back to the original question: why are more and more people using Docling?
Because it upgrades PDF parsing from "digging characters" to "restoring structure."
A PDF's value isn't in "how many characters it has," it's in "the relationships between characters." Which section a heading belongs to, which metric a number in a table corresponds to, which function this code belongs to: traditional tools drop these relationships, and Docling keeps them.
The structure that is kept directly sets the ceiling of a RAG system.
A table broken apart cannot be retrieved accurately no matter how strong the Embedding model is; a table with preserved structure can be used directly by the large model once retrieved.
Of course, Docling isn't the fastest, and complex tables aren't 100% accurate.
But for the need of "turning PDFs into RAG-usable data," Docling is currently one of the open-source options with the most complete structure preservation and the most mature ecosystem integration.
Reference resources:
Source: www.susan.net.cn