pdf-inspector
pdf-inspector 快速上手:先分类、再提取、最后路由 OCR
通过 CLI、Python、Node 或 Rust 运行结构化 PDF 流程。

你将学会
- Trace detection and layout stages
- Run native extraction and OCR safely
- Design provenance checks
开始前需要
- Basic Git and command-line usage
- Comfort reading a project README
You can explain the project, run its documented first step, and decide what to verify before adopting it.
先看结论
- Detection precedes extraction.
- Native parsing is the cheap default.
- OCR routing should remain page-specific.
Start with detection
先记录 PDF 类型、置信度和需 OCR 页,再生成 Markdown/JSON;只把扫描或坏编码页面送入 OCR 并保留页级来源。
Use the pinned source evidence, record versions and assumptions, and ask a qualified reviewer to validate the result before adopting it.
Extract locally
Use position-aware text and Markdown conversion for text PDFs. Enable `--analyze`, `--items-json`, `--pages`, or `--select-pages` only when the downstream consumer needs those fields.
Route only what needs OCR
Call the OCR path for scanned or broken-encoding pages and retain per-page provenance. Do not send every document to an external OCR service by default.
Use the pinned source evidence, record versions and assumptions, and ask a qualified reviewer to validate the result before adopting it.
如何选择
| 比较维度 | 方案 A | 方案 B |
|---|---|---|
| Best when | You need predictable behavior and easy auditing | You need adaptive optimization and have reliable telemetry |
| Main risk | May leave performance on the table | Can become difficult to explain or debug |
实施步骤
- 1
Install a matching binding or CLI.
- 2
Detect type and confidence.
- 3
Extract Markdown/JSON and inspect warnings.
- 4
Enable OCR only for routed pages.
可复制示例
pip install pdf-inspector
python - <<'PY'
import pdf_inspector
r = pdf_inspector.process_pdf('document.pdf')
print(r.pdf_type, r.markdown)
PY
detect-pdf document.pdf --analyze --json常见问题
Does every PDF need OCR?
No. Text-based pages can use native extraction; OCR is selective.
Can I parse only some pages?
Yes, the CLI documents `--select-pages` and related options.
资料来源
- pdf-inspector README (captured 2026-08-31)来源核查 2026-08-31
- pdf-inspector repository来源核查 2026-08-31