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())
使用するフラグ
--to md Markdown 出力を選択します。
期待される出力
# Annual Report
## Revenue
| Year | Revenue |
|---|---:|
| 2025 | $12M |
| 2026 | $15M |
バリエーション
速度のため OCR を省略
docling convert report.pdf --to md --no-ocrコピー
よくある間違い: スキャン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))
使用するフラグ
--to json ロスレス JSON 表現を出力します。
期待される出力
{
"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で到達可能な対応形式である必要があります。
公式ドキュメント · 対応フォーマット
スキャンPDFのOCR 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())
使用するフラグ
--no-ocr OCR ステージを完全にスキップします。
期待される出力
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とリーダーパッケージのバージョンを混在させること。両方を最新に保ってください。
公式ドキュメント · LangChain レシピ