Docling 文档解析与转换
Docling 是 IBM 开源的文档解析工具,把 PDF、DOCX、PPTX、HTML 等转换为结构化 Markdown/JSON,保留标题、表格、阅读顺序和版面信息。适合 RAG 的文档预处理。
它支持本地模型和 OCR,能处理扫描件和多栏排版,常与 LangChain/LlamaIndex 配合。
安装:
pip install docling
转换 PDF:
docling manual.pdf --output ./out --to markdown
转换并导出 JSON:
docling manual.pdf --output ./out --to json
Python API:
from docling.document_converter import DocumentConverter
converter = DocumentConverter()
result = converter.convert("manual.pdf")
print(result.document.export_to_markdown())
批量转换:
for f in docs/*.pdf; do
docling "$f" --output ./out --to markdown
done