pdf-inspector
pdf-inspector 详解:快速分类 PDF 并生成结构化 Markdown
介绍 Rust 解析、版面提取、选择性 OCR 和基准。

你将学会
- 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.
先看结论
- Native extraction and selective OCR are separate paths.
- Single-load parsing keeps layout and provenance coherent.
- Benchmarks require the same corpus and evaluator.
The short answer
pdf-inspector 是 Rust PDF 分类与提取库,支持文本/扫描检测、表格与版面分析、Markdown 输出,以及只对需要页面启用 OCR。
The README reports a 0.875 overall score and 0.470-second median corpus run for a specific 200-PDF benchmark. Treat those numbers as reproducibility targets, not a universal SLA.
Use the smallest interface
Install the Python package, Node package, Rust crate, or CLI. Start with `detect-pdf` and native `pdf2md` on a representative text PDF, then enable OCR only for pages that need it. Record package version, PDF hash, selected pages, OCR flag, and warnings.
Architecture and cost
The document is loaded once and shared between detection and extraction. Content streams produce text items and rectangles; font, layout, table, and Markdown stages build the final structure. Default Rust/browser builds avoid OCR dependencies, while PDFium, ONNX Runtime, and model files are touched only when OCR is routed.
When it fits
Use it for local ingestion of papers, invoices, financial or legal PDFs. Keep the original file and page-level provenance, and route low-confidence scans to a separately governed OCR pipeline rather than assuming perfect output.
如何选择
| 比较维度 | 方案 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 the matching binding or CLI.
- 2
Run detection and native extraction.
- 3
Enable OCR for routed pages only.
- 4
Retain hashes, warnings, and source PDFs.
可复制示例
cargo install pdf-inspector
pdf2md document.pdf --json
detect-pdf document.pdf --analyze --json常见问题
Does every PDF need OCR?
No. OCR is selective for scanned or image pages.
Are benchmark times portable?
No. Re-run with matching corpus, versions, hardware, and settings.
资料来源
- pdf-inspector README (captured 2026-08-31)来源核查 2026-08-31
- pdf-inspector repository来源核查 2026-08-31