PDF 转 Markdown PDF 与转换
从任何数字版 PDF 获得干净、可读的 Markdown。
适用场景: 当你需要从数字或混合 PDF 得到干净、可读的 Markdown 时。
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())
使用的标志
预期输出
# Annual Report
## Revenue
| Year | Revenue |
|---|---:|
| 2025 | $12M |
| 2026 | $15M |
变体
跳过 OCR 以提速
docling convert report.pdf --to md --no-ocr复制
常见错误: 对扫描 PDF 运行却得到空文本。如果 PDF 没有文本层,请使用 OCR(--ocr-mode full_page)。
官方文档 · PDF 转 JSON
PDF 转 JSON PDF 与转换
用于自定义流水线的完整 DoclingDocument 结构。
适用场景: 当你需要无损的 DoclingDocument 结构,包括边界框和版面元数据时。
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))
使用的标志
预期输出
{
"schema_name": "DoclingDocument",
"texts": [ ... ],
"tables": [ ... ]
}
变体
跳过 OCR 以提速
docling convert report.pdf --to json --no-ocr复制
常见错误: 期望 CLI 的 JSON 与 export_to_dict() 逐字节相同;它们是同一文档的等价表示。
官方文档 · PDF 转 Markdown
URL 转 Markdown PDF 与转换
直接从 HTTP URL 转换文档。
适用场景: 当文档在线上、你不想先下载时。
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())
预期输出
## Docling Technical Report
...
变体
改为导出 JSON
docling convert https://arxiv.org/pdf/2408.09869 --to json复制
常见错误: 认为任何 URL 都能用。源必须是可通过 HTTP 访问的受支持文档格式。
官方文档 · 支持的格式
带 OCR 的扫描 PDF OCR 与扫描
从纯图片页面恢复文本。
适用场景: 当页面是图像、没有可选文本时。
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())
使用的标志
--ocr-mode full_page 对每一页执行 OCR,即使已有文本。
预期输出
Text reconstructed from the scanned page image.
变体
选择其他引擎
docling convert scan.pdf --ocr-mode full_page --ocr-engine rapidocr复制
常见错误: 对数字 PDF 一直开启 OCR 会浪费时间。仅在缺少文本层时启用。
官方文档 · 对比 OCR 引擎
为数字 PDF 禁用 OCR OCR 与扫描
数字版 PDF 的转换速度大幅提升。
适用场景: 当 PDF 已有文本层、你想要最快转换时。
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())
使用的标志
预期输出
Markdown produced without running OCR.
变体
同时使用快速表格
docling convert report.pdf --no-ocr --table-mode fast复制
常见错误: 对扫描 PDF 禁用 OCR 会几乎得不到文本。
官方文档 · 所有命令
使用 HybridChunker 进行 RAG 分块 RAG
适用于向量库的结构感知分块。
适用场景: 当你想要保留标题、表格和页面元数据以供向量库使用的分块时。
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)
使用的标志
--to chunks 输出分块结果。--chunks-type hybrid 使用 HybridChunker。
预期输出
Chunks split on document structure rather than raw character counts.
变体
查看原始导出
docling convert report.pdf --to json复制
常见错误: 使用简单的字符分割而非结构感知分块,会破坏表格和标题。
官方文档 · RAG 指南
LangChain 集成 集成
将解析后的文档加载到 LangChain 流水线。
适用场景: 当你将解析后的文档载入 LangChain 流水线时。
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])
预期输出
LangChain Document objects with parsed page content and metadata.
变体
然后转换文件
docling convert report.pdf --to md复制
常见错误: 忘记单独安装与 docling 分离的集成包。
官方文档 · LlamaIndex 示例
LlamaIndex 集成 集成
从解析后的文件构建 LlamaIndex 节点。
适用场景: 当你从解析后的文件构建 LlamaIndex 文档节点时。
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])
预期输出
LlamaIndex documents ready for indexing.
变体
然后转换文件
docling convert report.pdf --to md复制
常见错误: 混用 docling 与 reader 包的版本;请让两者都保持最新。
官方文档 · LangChain 示例