pdfmux
pdfmux
汎用PDF抽出オーケストレーター。各ページを最適なバックエンドにルーティングし、出力を監査し、失敗した場合は再抽出を行います。5つのルールベース抽出ツールとBYOK(Bring Your Own Key)LLMフォールバックを搭載。CLIは1つ、APIは1つ、設定は不要です。
PDF ──> pdfmux router ──> best extractor per page ──> audit ──> re-extract failures ──> Markdown / JSON / chunks
|
├─ PyMuPDF (digital text, 0.01s/page)
├─ OpenDataLoader (complex layouts, 0.05s/page)
├─ RapidOCR (scanned pages, CPU-only)
├─ Docling (tables, 97.9% TEDS)
├─ Surya (heavy OCR fallback)
└─ YOUR LLM (Gemini / Claude / GPT-4o / Ollama — BYOK via 5-line YAML)インストール
pip install pdfmux以上です。デジタルPDFはそのまま処理できます。より複雑なドキュメントにはバックエンドを追加してください:
pip install "pdfmux[ocr]" # RapidOCR — scanned/image pages (~200MB, CPU-only)
pip install "pdfmux[tables]" # Docling — table-heavy docs (~500MB)
pip install "pdfmux[opendataloader]" # OpenDataLoader — complex layouts (Java 11+)
pip install "pdfmux[llm]" # LLM fallback — Gemini, Claude, GPT-4o, Ollama
pip install "pdfmux[all]" # everythingPython 3.11以上が必要です。
クイックスタート
CLI
# zero config — just works
pdfmux convert invoice.pdf
# invoice.pdf -> invoice.md (2 pages, 95% confidence, via pymupdf4llm)
# RAG-ready chunks with token limits
pdfmux convert report.pdf --chunk --max-tokens 500
# cost-aware extraction with budget cap
pdfmux convert report.pdf --mode economy --budget 0.50
# schema-guided structured extraction (5 built-in presets)
pdfmux convert invoice.pdf --schema invoice
# BYOK any LLM for hardest pages
pdfmux convert scan.pdf --llm-provider claude
# batch a directory
pdfmux convert ./docs/ -o ./output/Python
import pdfmux
# text -> markdown
text = pdfmux.extract_text("report.pdf")
# structured data -> dict with tables, key-values, metadata
data = pdfmux.extract_json("report.pdf")
# RAG chunks -> list of dicts with token estimates
chunks = pdfmux.chunk("report.pdf", max_tokens=500)アーキテクチャ
┌─────────────────────────────┐
│ Segment Detector │
│ text / tables / images / │
│ formulas / headers per page │
└─────────────┬───────────────┘
│
┌────────────────────────────────────────┐
│ Router Engine │
│ │
│ economy ── balanced ── premium │
│ (minimize $) (default) (max quality)│
│ budget caps: --budget 0.50 │
└────────────────────┬───────────────────┘
│
┌──────────┬──────────┬────────┴────────┬──────────┐
│ │ │ │ │
PyMuPDF OpenData RapidOCR Docling LLM
digital Loader scanned tables (BYOK)
0.01s/pg complex CPU-only 97.9% any provider
layouts TEDS
│ │ │ │ │
└──────────┴──────────┴────────┬────────┴──────────┘
│
┌────────────────────────────────────────┐
│ Quality Auditor │
│ │
│ 4-signal dynamic confidence scoring │
│ per-page: good / bad / empty │
│ if bad -> re-extract with next backend│
└────────────────────┬───────────────────┘
│
┌────────────────────────────────────────┐
│ Output Pipeline │
│ │
│ heading injection (font-size analysis)│
│ table extraction + normalization │
│ text cleanup + merge │
│ confidence score (honest, not inflated)│
└────────────────────────────────────────┘主要な設計上の決定
抽出ツールではなく、ルーター。 pdfmuxはPyMuPDFやDoclingと競合しません。ページごとに最適なツールを選択します。
エージェントによるマルチパス。 抽出、信頼性の監査、失敗した場合はより強力なバックエンドで再抽出を行います。問題のあるページは自動的に再試行されます。
セグメントレベルの検出。 各ページはルーティングの前にコンテンツタイプ(テキスト、表、画像、数式、ヘッダー)によって分類されます。
4つの信号による信頼性スコアリング。 文字密度、OCRノイズ比、表の整合性、見出し構造から動的な品質スコアリングを行います。ハードコードされたしきい値ではありません。
ドキュメントキャッシュ。 各PDFは抽出ツールごとに開かれるのではなく、一度だけ開かれます。パイプライン全体で共有されます。
データフライホイール。 ローカルのテレメトリがドキュメントタイプごとにどの抽出ツールが優れているかを追跡します。使用するほどルーティングが向上します。
機能
機能 | 内容 | コマンド |
設定不要の抽出 | 自動的に最適なバックエンドへルーティング |
|
RAGチャンキング | トークン見積もり付きのセクション認識チャンク |
|
コストモード | 予算上限付きのeconomy / balanced / premium |
|
スキーマ抽出 | 5つの組み込みプリセット(請求書、領収書、契約書、履歴書、論文) |
|
BYOK LLM | Gemini、Claude、GPT-4o、Ollama、OpenAI互換API |
|
ベンチマーク | インストール済みの全抽出ツールを正解データと比較評価 |
|
Doctor | インストール済みバックエンド、カバレッジの欠落、推奨事項を表示 |
|
MCPサーバー | AIエージェントがstdioまたはHTTP経由でPDFを読み取り |
|
バッチ処理 | ディレクトリ全体の変換 |
|
ストリーミング | 大規模ファイル向けのメモリ制限付きページ反復処理 |
|
CLIリファレンス
pdfmux convert
pdfmux convert <file-or-dir> [options]
Options:
-o, --output PATH Output file or directory
-f, --format FORMAT markdown | json | csv | llm (default: markdown)
-q, --quality QUALITY fast | standard | high (default: standard)
-s, --schema SCHEMA JSON schema file or preset (invoice, receipt, contract, resume, paper)
--chunk Output RAG-ready chunks
--max-tokens N Max tokens per chunk (default: 500)
--mode MODE economy | balanced | premium (default: balanced)
--budget AMOUNT Max spend per document in USD
--llm-provider PROVIDER LLM backend: gemini | claude | openai | ollama
--confidence Include confidence score in output
--stdout Print to stdout instead of filepdfmux serve
AIエージェント統合用のMCPサーバーを起動します。
pdfmux serve # stdio mode (Claude Desktop, Cursor)
pdfmux serve --http 8080 # HTTP modepdfmux doctor
pdfmux doctor
# ┌──────────────────┬─────────────┬─────────┬──────────────────────────────────┐
# │ Extractor │ Status │ Version │ Install │
# ├──────────────────┼─────────────┼─────────┼──────────────────────────────────┤
# │ PyMuPDF │ installed │ 1.25.3 │ │
# │ OpenDataLoader │ installed │ 0.3.1 │ │
# │ RapidOCR │ installed │ 3.0.6 │ │
# │ Docling │ missing │ -- │ pip install pdfmux[tables] │
# │ Surya │ missing │ -- │ pip install pdfmux[ocr-heavy] │
# │ LLM (Gemini) │ configured │ -- │ GEMINI_API_KEY set │
# └──────────────────┴─────────────┴─────────┴──────────────────────────────────┘pdfmux benchmark
pdfmux benchmark report.pdf
# ┌──────────────────┬────────┬────────────┬─────────────┬──────────────────────┐
# │ Extractor │ Time │ Confidence │ Output │ Status │
# ├──────────────────┼────────┼────────────┼─────────────┼──────────────────────┤
# │ PyMuPDF │ 0.02s │ 95% │ 3,241 chars │ all pages good │
# │ Multi-pass │ 0.03s │ 95% │ 3,241 chars │ all pages good │
# │ RapidOCR │ 4.20s │ 88% │ 2,891 chars │ ok │
# │ OpenDataLoader │ 0.12s │ 97% │ 3,310 chars │ best │
# └──────────────────┴────────┴────────────┴─────────────┴──────────────────────┘Python API
テキスト抽出
import pdfmux
text = pdfmux.extract_text("report.pdf") # -> str (markdown)
text = pdfmux.extract_text("report.pdf", quality="fast") # PyMuPDF only, instant
text = pdfmux.extract_text("report.pdf", quality="high") # LLM-assisted構造化抽出
data = pdfmux.extract_json("report.pdf")
# data["page_count"] -> 12
# data["confidence"] -> 0.91
# data["ocr_pages"] -> [2, 5, 8]
# data["pages"][0]["key_values"] -> [{"key": "Date", "value": "2026-02-28"}]
# data["pages"][0]["tables"] -> [{"headers": [...], "rows": [...]}]RAGチャンキング
chunks = pdfmux.chunk("report.pdf", max_tokens=500)
for c in chunks:
print(f"{c['title']}: {c['tokens']} tokens (pages {c['page_start']}-{c['page_end']})")スキーマガイド付き抽出
data = pdfmux.extract_json("invoice.pdf", schema="invoice")
# Uses built-in invoice preset: extracts date, vendor, line items, totals
# Also accepts a path to a custom JSON Schema fileストリーミング(メモリ制限付き)
from pdfmux.extractors import get_extractor
ext = get_extractor("fast")
for page in ext.extract("large-500-pages.pdf"): # Iterator[PageResult]
process(page.text) # constant memory, even on 500-page PDFs型とエラー
from pdfmux import (
# Enums
Quality, # FAST, STANDARD, HIGH
OutputFormat, # MARKDOWN, JSON, CSV, LLM
PageQuality, # GOOD, BAD, EMPTY
# Data objects (frozen dataclasses)
PageResult, # page: text, page_num, confidence, quality, extractor
DocumentResult, # document: pages, source, confidence, extractor_used
Chunk, # chunk: title, text, page_start, page_end, tokens
# Errors
PdfmuxError, # base -- catch this for all pdfmux errors
FileError, # file not found, unreadable, not a PDF
ExtractionError, # extraction failed
ExtractorNotAvailable,# requested backend not installed
FormatError, # invalid output format
AuditError, # audit could not complete
)フレームワーク統合
LangChain
pip install langchain-pdfmuxfrom langchain_pdfmux import PDFMuxLoader
loader = PDFMuxLoader("report.pdf", quality="standard")
docs = loader.load() # -> list[Document] with confidence metadataLlamaIndex
pip install llama-index-readers-pdfmuxfrom llama_index.readers.pdfmux import PDFMuxReader
reader = PDFMuxReader(quality="standard")
docs = reader.load_data("report.pdf") # -> list[Document]MCPサーバー(AIエージェント)
mcpservers.orgに掲載されています。1行でセットアップ可能:
{
"mcpServers": {
"pdfmux": {
"command": "npx",
"args": ["-y", "pdfmux-mcp"]
}
}
}またはClaude Code経由:
claude mcp add pdfmux -- npx -y pdfmux-mcp公開されるツール: convert_pdf, analyze_pdf, extract_structured, get_pdf_metadata, batch_convert。
BYOK LLM設定
pdfmuxは5行のYAMLで任意のLLMをサポートします。独自のキーを使用してください。設定しない限り、データがマシンから外部へ送信されることはありません。
# ~/.pdfmux/llm.yaml
provider: claude # gemini | claude | openai | ollama | any OpenAI-compatible
model: claude-sonnet-4-20250514
api_key: ${ANTHROPIC_API_KEY}
base_url: https://api.anthropic.com # optional, for custom endpoints
max_cost_per_page: 0.02 # budget capサポートされているプロバイダー:
プロバイダー | モデル | ローカル? | コスト |
Gemini | 2.5 Flash, 2.5 Pro | いいえ | ~$0.01/ページ |
Claude | Sonnet, Opus | いいえ | ~$0.015/ページ |
GPT-4o | GPT-4o, GPT-4o-mini | いいえ | ~$0.01/ページ |
Ollama | 任意のローカルモデル | はい | 無料 |
カスタム | 任意のOpenAI互換API | 設定可能 | 変動 |
ベンチマーク
opendataloader-benchでテスト済み。財務報告書、法的書類、学術論文、スキャン文書など、200の実世界のPDFを使用。
エンジン | 総合 | 読み取り順序 | 表 (TEDS) | 見出し | 必要条件 |
opendataloader hybrid | 0.909 | 0.935 | 0.928 | 0.828 | API呼び出し ($) |
pdfmux | 0.905 | 0.920 | 0.911 | 0.852 | CPUのみ, $0 |
docling | 0.877 | 0.900 | 0.887 | 0.802 | ~500MB モデル |
marker | 0.861 | 0.890 | 0.808 | 0.796 | GPU推奨 |
opendataloader local | 0.844 | 0.913 | 0.494 | 0.761 | CPUのみ |
mineru | 0.831 | 0.857 | 0.873 | 0.743 | GPU + ~2GB モデル |
総合2位、無料ツールの中では1位。有料1位のスコアの99.5%をコストゼロで達成。テストされた全エンジンの中で最高の見出し検出精度。画像として埋め込まれた表もOCRで抽出可能。
信頼性スコアリング
すべての結果には4つの信号による信頼性スコアが含まれます:
95-100% -- クリーンなデジタルテキスト、完全に抽出可能
80-95% -- 良好な抽出、一部のページに軽微なOCRノイズあり
50-80% -- 部分的な抽出、一部のページは復元不能
<50% -- コンテンツが大幅に欠落、警告が含まれる
信頼性が80%を下回ると、pdfmuxは何が問題でどう修正すべきかを正確に伝えます:
Page 4: 32% confidence. 0 chars extracted from image-heavy page.
-> Install pdfmux[ocr] for RapidOCR support on 6 image-heavy pages.コストモード
モード | 動作 | 通常のコスト |
economy | ルールベースのバックエンドのみ。LLM呼び出しなし。 | $0/ページ |
balanced | ルールベース抽出に失敗したページのみLLMを使用。 | ~$0.002/ページ (平均) |
premium | 最大品質のため全ページでLLMを使用。 | ~$0.01/ページ |
予算上限の設定:--budget 0.50 を指定すると、ドキュメントあたりの支出が$0.50に達した時点でLLM呼び出しを停止します。
なぜpdfmuxなのか?
pdfmuxは単なるPDF抽出ツールではありません。ページごとに適切な抽出ツールを選択し、結果を検証し、失敗を再試行するオーケストレーション層です。
ツール | 強み | 制限 |
PyMuPDF | 高速なデジタルテキスト | スキャンや画像レイアウトを扱えない |
Docling | 表 (精度97.9%) | 表以外のドキュメントでは低速 |
Marker | GPU ML抽出 | GPUが必要、デジタルPDFには過剰 |
Unstructured | エンタープライズプラットフォーム | 設定が複雑、有料ティアあり |
LlamaParse | クラウドネイティブ | APIキーが必要、ローカル不可 |
Reducto | 高精度 | $0.015/ページ、クローズドソース |
pdfmux | 上記すべてをオーケストレート | ページごとのルーティング、監査、再抽出 |
Reductoのオープンソース代替:他で$0.015/ページかかるものが、pdfmuxのルールベースバックエンドなら無料、BYOK LLMフォールバックなら平均~$0.002/ページです。
開発
git clone https://github.com/NameetP/pdfmux.git
cd pdfmux
python3.12 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest # 151 tests
ruff check src/ tests/
ruff format src/ tests/貢献
リポジトリをフォーク
ブランチを作成 (
git checkout -b feature/your-feature)新機能のテストを記述
pytestとruff checkがパスすることを確認PRを作成
ライセンス
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/NameetP/pdfmux'
If you have feedback or need assistance with the MCP directory API, please join our Discord server