pdf-inspector 上手指南:30秒判断PDF类型,200ms提取Markdown

发布时间:2026/9/8 21:11:56
pdf-inspector 上手指南:30秒判断PDF类型,200ms提取Markdown pdf-inspector 上手指南30秒判断PDF类型200ms提取Markdown【免费下载链接】pdf-inspectorFast Rust library for PDF inspection, classification, and text extraction. Intelligently detects scanned vs text-based PDFs to enable smart routing decisions.项目地址: https://gitcode.com/GitHub_Trending/pdf/pdf-inspector拿到一份PDF先要弄清它能不能直接提取文字文本型PDF可以完全本地处理扫描型PDF则必须走OCR。pdf-inspector 是一款Rust PDF解析库核心能力是PDF类型识别、文本提取与Markdown转换适合需要用Python或Node.js在本地批量处理PDF的开发者。它把文本型PDF的完整处理压缩到200ms以内类型判断通常只需10-50ms并在200份测试文档上取得了0.875的整体得分。一条命令完成安装Python、Node.js 与浏览器三个运行环境各有一条安装命令按需取用运行环境安装命令Pythonpip install pdf-inspectorNode.jsnpm install firecrawl/pdf-inspector浏览器 WebAssemblynpm install firecrawl/pdf-inspector-wasm如果你要在仓库源码上二次开发Python 侧改用源码构建先执行pip install maturin再执行maturin develop --release。最小示例一次调用返回PDF类型与Markdown以 Python 为例process_pdf一步完成识别、提取和转换import pdf_inspector result pdf_inspector.process_pdf(document.pdf) print(result.pdf_type) # text_based, scanned, image_based, mixed print(result.markdown) # Markdown字符串或None返回对象中你最关心的几个字段字段含义pdf_typePDF类型取值为text_based、scanned、image_based、mixed四种markdown转换后的Markdown字符串无法提取时为Noneconfidence识别置信度0.0-1.0needs_ocr是否需要走OCR流程Node.js 侧的调用方式对应安装后执行processPdf(readFileSync(document.pdf))返回的pdfType取值为 TextBased、Scanned、ImageBased、Mixed另外提供classifyPdf做轻量分类完整说明见 napi/README.md。 30秒判断PDF类型只用快速检测模式如果下游只需要一个路由决策——本地提取还是送去OCR——不必跑完整提取流程用快速检测模式即可detection pdf_inspector.detect_pdf_type(document.pdf) print(detection.pdf_type) # PDF类型 print(detection.confidence) # 置信度0.0-1.0 print(detection.needs_ocr) # 是否需要OCR判定结果只有类型、置信度和OCR标记三行每次开销在毫秒级适合放进批量处理管线做分流。进阶任务只处理指定页面、拿到文字坐标两个最常用的进阶调用替换入口参数或函数即可# 只处理第1-3页0索引 result pdf_inspector.process_pdf(document.pdf, pages[0, 1, 2]) # 获取带位置信息的文本项 items pdf_inspector.extract_text_items(document.pdf) for item in items: print(item.text, item.x, item.y, item.font_name)pages参数限制处理范围在长文档上能省下大量时间extract_text_items返回的每个条目都带 X/Y 坐标和字体名做高亮、检索或二次排版时可以直接取用。 浏览器本地解析WebAssembly 用法WebAssembly 版把同一套解析逻辑跑在浏览器里不需要服务器往返import init, { processPdf } from firecrawl/pdf-inspector-wasm; await init(); const response await fetch(/document.pdf); const pdf new Uint8Array(await response.arrayBuffer()); const result processPdf(pdf); console.log(result.pdfType, result.markdown);init()只需调用一次之后processPdf接收Uint8Array返回与 Node.js 相同结构的pdfType和markdown接入细节见 wasm/README.md。继续深入官方文档与基准测试资料解决什么问题docs/python.md完整Python API各入口函数与返回类型napi/README.mdNode.js 绑定的接口与示例wasm/README.mdWebAssembly 在浏览器中的接入细节docs/benchmarking.md如何复现和对比性能基准测试到这里类型识别、Markdown提取、坐标定位三个任务各有一段可运行的代码。下一步建议把process_pdf接进你的文档处理管线遇到具体函数签名时再查 docs/python.md。【免费下载链接】pdf-inspectorFast Rust library for PDF inspection, classification, and text extraction. Intelligently detects scanned vs text-based PDFs to enable smart routing decisions.项目地址: https://gitcode.com/GitHub_Trending/pdf/pdf-inspector创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考