pdf-inspector CLI 教程 - pdf2md 与 detect-pdf
API 参考CLI
pdf-inspector 自带两个命令行工具,随 crate 一起发布——cargo install pdf-inspector 一条命令装好,不用写任何代码就能完成 PDF 分类和 Markdown 转换。npm 包也内置了 CLI,装 Node 版同样能用。
安装
# Rust 工具链用户
cargo install pdf-inspector
# 或 Node 用户(npm 包内置)
npm install -g @firecrawl/pdf-inspector装完会得到两个可执行文件:
| 工具 | 干什么 | 典型耗时 |
|---|---|---|
detect-pdf | 判定文档类型 + 分析信息 | ~10–50ms |
pdf2md | 完整解析,输出 Markdown | 文本型 <200ms |
detect-pdf:先问一句「能不能直接提」
# 快速判定
detect-pdf document.pdf
# 带分析信息 + JSON 输出(推荐)
detect-pdf document.pdf --analyze --jsonJSON 输出里最有用的是这几项:
{
"pdfType": "TextBased",
"confidence": 0.92,
"pagesNeedingOcr": []
}拿到 TextBased 就放心跑 pdf2md;拿到 Scanned / Mixed 就知道哪些页要送 OCR——这条「先判定再路由」的链路是官方推荐的省钱姿势。
pdf2md:一条命令转 Markdown
# 输出到终端
pdf2md annual-report.pdf
# 输出到文件
pdf2md annual-report.pdf -o report.md
# 只处理部分页
pdf2md annual-report.pdf --pages 1-3
# 结构化 JSON(含元数据,方便程序消费)
pdf2md annual-report.pdf --json
# 省 token 的紧凑输出(喂 LLM 前)
pdf2md annual-report.pdf --compact参数速查
| 用法 | 说明 |
|---|---|
pdf2md <file> | 解析文件,Markdown 到 stdout |
pdf2md <file> -o out.md | 输出到指定文件 |
pdf2md <file> --pages 1-3 | 只处理指定页 |
pdf2md <file> --select-pages | 交互式选择页 |
pdf2md <file> --compact | 紧凑模式,省 token |
pdf2md <file> --json | 结构化 JSON 输出 |
detect-pdf <file> | 快速类型判定 |
detect-pdf <file> --analyze --json | 判定 + 分析信息 |
常见组合
批量转换目录
for f in *.pdf; do
pdf2md "$f" -o "${f%.pdf}.md"
done先判定再转换的路由脚本
type=$(detect-pdf "$f" --analyze --json | jq -r '.pdfType')
if [ "$type" = "TextBased" ]; then
pdf2md "$f" -o "${f%.pdf}.md"
else
echo "跳过 $f:$type 需要 OCR"
fi接进管道
pdf2md annual-report.pdf --compact | your-llm-loader小提示
- 首次
cargo install需要编译几分钟,之后就是原生速度 - Windows / macOS ARM / Linux x64·ARM64 都有预编译二进制,npm 方式免编译
- 更多参数以官方仓库 README 与
--help输出为准