Overview
pdf-inspector is a high-performance Rust library designed for efficient PDF analysis. It excels at classifying PDFs into types like Text-Based, Scanned, Image-Based, or Mixed, and can extract text with remarkable accuracy. A standout feature is its ability to intelligently detect scanned versus text-based documents, enabling smart routing decisions in processing pipelines and significantly reducing the need for expensive OCR services for PDFs that don't require it. With bindings for Python, Node.js, and WebAssembly, it offers a versatile solution for local PDF processing.
Key Features
- Intelligent PDF Classification: Quickly determines PDF type (TextBased, Scanned, ImageBased, Mixed) with confidence scores and per-page OCR routing suggestions, all in milliseconds.
- Accurate Text Extraction: Extracts text while preserving positional awareness, font information, and automatically determining reading order for multi-column layouts.
- Rich Markdown Conversion: Transforms PDF content into clean Markdown, intelligently identifying headings (H1-H4), lists, code blocks, tables, bold/italic formatting, and links.
- Advanced Table Detection: Features dual-mode table detection, combining rectangle-based analysis of drawing operations with heuristic detection from text alignment, capable of handling complex financial tables and multi-page continuations.
- Broad Encoding Support: Decodes common CID font encodings, including ToUnicode CMap, ensuring accurate text retrieval across a wide range of PDFs.
- Optimized for Speed & Efficiency: Built in pure Rust, it offers exceptional performance, processing text-based PDFs locally in under 200ms without external dependencies or ML models.
- Browser & Serverless Ready: With WebAssembly support, it can run directly in the browser or in serverless environments, eliminating the need for server round trips.
Typical Use Cases
pdf-inspector is ideal for applications requiring efficient and intelligent PDF processing at scale. Its primary use case is in smart PDF routing pipelines, where the ability to quickly distinguish between text-based and scanned documents allows for significant cost and latency savings by selectively applying OCR only when necessary.
This makes it a powerful tool for:
- Document Processing Services: Routing documents to the appropriate processing path (e.g., local extraction vs. OCR) based on content type.
- Data Extraction Platforms: Extracting structured data from reports, research papers, financial documents, invoices, and legal texts with high fidelity.
- Content Management Systems: Indexing and searching PDF content efficiently by converting them to structured Markdown.
- Local PDF Analysis: Enabling users to analyze and convert PDFs directly in the browser or via lightweight command-line tools without relying on server-side infrastructure.
