firecrawl/pdf-inspector
Fast Rust library for PDF inspection, classification, and text extraction. Intelligently detects scanned vs text-based PDFs to enable smart routing decisions.
pdf‑inspector – Fast, smart PDF classification & extraction
What it does
- Quickly decides whether a PDF is text‑based, scanned, image‑based or a mix (10‑50 ms) and gives a confidence score.
- For text‑based PDFs it extracts the text with layout information (font, X/Y coordinates, rotation) and turns the document into clean Markdown.
- Detects headings, lists, code blocks, tables (both rectangle‑based and heuristic), bold/italic, URLs, page breaks, etc.
- Optional selective OCR: only pages that lack extractable text are sent to a local PP‑OCRv6 model, avoiding full‑document OCR latency.
- Available as a native Rust crate, a CLI (
pdf2md/detect-pdf), Python and Node.js packages, and a WebAssembly build for browsers.
Why it matters
- About half of PDFs on the web are already text‑based; running OCR on all of them wastes CPU and money. pdf‑inspector lets you route only the truly scanned pages to OCR, cutting cost and latency.
- The library keeps the PDF parsed once, sharing that representation between detection and extraction, which speeds up the whole pipeline.
- Benchmarks on a 200‑PDF corpus show it out‑performs comparable tools in overall quality, reading order, table handling, and speed (0.47 s for the whole set vs. several seconds for alternatives).
How to use it
- Rust:
cargo add pdf-inspector; callprocess_pdf("file.pdf")to getpdf_typeand optional Markdown. - Python:
pip install pdf-inspector;pdf_inspector.process_pdf("file.pdf"). - Node:
npm install @firecrawl/pdf-inspector;processPdf(buffer). - Browser: import the WASM package and call
processPdf(uint8Array). - CLI:
pdf2md file.pdffor Markdown,detect-pdf file.pdffor just the classification.
Key technical bits
- Classification samples a few pages, looks for text (
Tj/TJ) vs. image (Do) operators. - Extraction walks the PDF content stream, builds
TextItems with font metrics and positions, then groups them into lines, columns, and tables. - Table detection combines rectangle detection from drawing commands with heuristic alignment of text.
- Markdown conversion uses font‑size ratios for heading levels and font‑name patterns for bold/italic.
When to pick it
- You need fast, local processing of large batches of PDFs (reports, research papers, invoices, legal docs).
- You want structured Markdown with tables and proper reading order without paying for a cloud OCR service.
- You run in environments where Rust, Python, Node, or the browser are available, and you can install the optional PDFium/ONNX Runtime libraries for OCR when needed.
License: MIT.
Related
- Project
- Project
- Project
- Project
- Project