Introduction
pdf-inspector is an open-source Rust library with Python bindings for inspecting and classifying PDF documents. Built by the Firecrawl team, it detects whether a PDF contains extractable text or is a scanned image, enabling intelligent routing to the right processing pipeline. This avoids wasting OCR resources on text-based PDFs and missing content in scanned ones.
What pdf-inspector Does
- Classifies PDFs as text-based, scanned, or mixed content
- Extracts text from text-based PDFs without OCR overhead
- Provides page-level metadata including dimensions and content type
- Offers both Rust and Python APIs for integration flexibility
- Processes documents with minimal memory and CPU usage
Architecture Overview
The library is written in Rust for performance and safety, with Python bindings generated via PyO3. It parses the PDF structure directly to detect embedded text streams versus image-only pages. Classification uses heuristics based on text density per page area, avoiding the need for machine learning models while maintaining high accuracy.
Self-Hosting & Configuration
- Install via pip for Python projects or Cargo for Rust projects
- No external dependencies or services required
- Configure classification thresholds via the API for edge cases
- Integrate into existing document processing pipelines as a pre-filter
- Works on Linux, macOS, and Windows
Key Features
- Sub-second classification for most documents
- Zero external dependencies beyond the PDF parser
- Accurate mixed-content detection at the page level
- Node.js bindings available alongside Python and Rust
- Thread-safe for concurrent document processing
Comparison with Similar Tools
- PyMuPDF (fitz) — Full-featured PDF library; pdf-inspector focuses specifically on classification and routing
- pdfplumber — Python-only text extraction; pdf-inspector adds classification and is faster via Rust
- Apache Tika — JVM-based with broad format support; pdf-inspector is lightweight and PDF-specific
- Docling — AI-powered document parsing; pdf-inspector is a simpler heuristic-based pre-filter
FAQ
Q: When should I use pdf-inspector instead of a full PDF library? A: When you need to decide how to process a PDF before extracting content, for example routing scanned PDFs to OCR and text PDFs to a text extractor.
Q: Does it handle encrypted PDFs? A: It can inspect unencrypted PDFs and password-protected ones if you provide the password.
Q: How accurate is the classification? A: It achieves high accuracy on common document types using text density heuristics without needing ML models.
Q: Can I use it in a serverless environment? A: Yes. The library has no external dependencies and starts instantly.