Favicon of pdf-inspector

pdf-inspector

Rust library and CLI for PDF classification and text/Markdown extraction, with optional selective OCR for scanned pages. Bindings for Python, Node.js, and WASM.

pdf-inspector website screenshot
pdf-inspector GitHub repository preview

pdf-inspector is a Rust library for inspecting PDFs: it figures out whether a document is text-based, scanned, image-based, or mixed, then extracts text or converts to Markdown accordingly. It's built by Firecrawl for pipelines that process PDFs at scale and want to skip OCR for the majority of documents that don't need it. It targets backend developers, data pipeline builders, and anyone building document ingestion for RAG, search, or archival systems, with bindings for Rust, Python, Node.js, and browser WebAssembly.

Key features

  • Smart classification: detects TextBased, Scanned, ImageBased, or Mixed PDFs in roughly 10-50ms by sampling content streams, with a confidence score and per-page OCR routing.
  • Position-aware text extraction: captures font info, X/Y coordinates, multi-column reading order, and rotation angles for rotated text runs like margin stamps.
  • Markdown conversion: renders headings, lists, code blocks, tables, bold/italic, and URL links from PDF structure, no OCR needed for text-based files.
  • Table detection: combines rectangle-based detection from drawing operators with heuristic detection from text alignment, handling financial tables and multi-page continuations.
  • CID font support: decodes ToUnicode CMaps for Type0/Identity-H fonts across UTF-16BE, UTF-8, and Latin-1 encodings.
  • Encoding issue detection: flags broken font encodings automatically so a caller can fall back to OCR.
  • Selective OCR: renders and OCRs only the pages that need it (via PP-OCRv6 Small), preserving per-page provenance and hosted-fallback recommendations.
  • Single document load: parses the PDF once and shares it between detection and extraction stages.
  • Browser WebAssembly build: runs the same Rust parser client-side with embedded CMaps, no server round trip.
  • Lightweight default builds: Rust and browser builds stay pure-extraction; PDFium, ONNX Runtime, and model files load only when a page is actually routed to OCR.

Ideal use cases

Use pdf-inspector when you're building an ingestion pipeline that needs to classify PDFs before deciding how to process them, for example routing text-based reports, invoices, legal documents, or research papers to fast local extraction while sending truly scanned pages to an OCR service. It fits well when you need structured Markdown output with headings, tables, and lists preserved rather than a flat text dump, and when you care about latency (extraction runs in roughly 150ms for text-based PDFs versus seconds for OCR).

It's also a good fit if you want a single parser shared across Rust, Python, Node.js, and browser environments, since the core logic is written once and exposed through consistent bindings.

It's not the right tool if your PDFs are predominantly scanned images and you need full-document OCR as the primary path; the default builds are extraction-focused and OCR is an opt-in add-on that still requires separately installed PDFium and ONNX Runtime binaries. It also isn't a general PDF editing or generation library, it's read-only inspection and extraction.

Installation

Python:

pip install pdf-inspector
import pdf_inspector
result = pdf_inspector.process_pdf("document.pdf")
print(result.pdf_type)
print(result.markdown)

Node.js:

npm install @firecrawl/pdf-inspector
import { readFileSync } from 'fs';
import { processPdf } from '@firecrawl/pdf-inspector';
const pdf = readFileSync('document.pdf');
const result = processPdf(pdf);
console.log(result.markdown);

Browser WebAssembly:

npm install @firecrawl/pdf-inspector-wasm

Rust:

cargo add pdf-inspector

CLI:

cargo install pdf-inspector
pdf2md document.pdf
detect-pdf document.pdf --json

For OCR support in Rust/CLI, build with the ocr feature and provide PDFium and ONNX Runtime library paths:

cargo install pdf-inspector --features ocr --bin pdf2md
PDFIUM_LIB_PATH=/path/to/libpdfium ORT_DYLIB_PATH=/path/to/libonnxruntime \
  pdf2md scan.pdf --ocr auto --json

Python and Node packages include the OCR pipeline natively but still need PDFium and ONNX Runtime available at runtime when a page is routed to OCR.

Frequently asked questions

Share:

Stars
19.7K
Forks
1.3K
Last commit
11 days ago
Repository age
8 months
License
MIT
Self-hosted
No
Activity score
81/100
View Repository
Ad
Favicon

 

  
 

Similar to pdf-inspector

Favicon

 

  
 
Favicon

 

  
 
Favicon