{"name":"pdf-inspector: Fast Rust Library for PDF Classification and Text Extraction","description":"pdf-inspector is a high-performance Rust library designed for intelligent PDF processing. It excels at classifying PDFs as text-based or scanned, extracting text with position awareness, and converting content to clean Markdown. This library enables smart routing decisions, significantly reducing the need for expensive OCR services for many documents.","github":"https://github.com/firecrawl/pdf-inspector","url":"https://osrepos.com/repo/firecrawl-pdf-inspector","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/firecrawl-pdf-inspector","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/firecrawl-pdf-inspector.md","json":"https://osrepos.com/repo/firecrawl-pdf-inspector.json","topics":["Rust","PDF","Text Extraction","PDF Classification","Markdown Conversion","OCR Routing","Python Bindings","Node.js Bindings"],"keywords":["Rust","PDF","Text Extraction","PDF Classification","Markdown Conversion","OCR Routing","Python Bindings","Node.js Bindings"],"stars":null,"summary":"pdf-inspector is a high-performance Rust library designed for intelligent PDF processing. It excels at classifying PDFs as text-based or scanned, extracting text with position awareness, and converting content to clean Markdown. This library enables smart routing decisions, significantly reducing the need for expensive OCR services for many documents.","content":"## Introduction\n\n`pdf-inspector` is a high-performance Rust library developed by Firecrawl, designed for efficient PDF inspection, classification, and text extraction. It intelligently distinguishes between scanned and text-based PDFs, enabling smart routing decisions that can significantly reduce reliance on expensive OCR services. This library offers robust capabilities for converting PDF content into clean Markdown, complete with structured elements like headings, lists, and tables. Beyond its native Rust interface, `pdf-inspector` provides convenient bindings for Python, Node.js, and browser WebAssembly, making it accessible across various development environments. Its impressive benchmark results highlight its speed and accuracy in handling complex PDF layouts.\n\n## Installation\n\nGetting started with `pdf-inspector` is straightforward across its supported platforms.\n\n### Python\n\nbash\npip install pdf-inspector\n\n\n### Node.js\n\nbash\nnpm install @firecrawl/pdf-inspector\n\n\n### Browser WebAssembly\n\nbash\nnpm install @firecrawl/pdf-inspector-wasm\n\n\n### Rust\n\nAdd to your `Cargo.toml`:\n\ntoml\n[dependencies]\npdf-inspector = \"1\"\n\n\nOr install via `cargo add`:\n\nbash\ncargo add pdf-inspector\n\n\n### CLI\n\nbash\ncargo install pdf-inspector\n\n\nFor full API references, please consult the official documentation:\n*   [Python API Reference](https://github.com/firecrawl/pdf-inspector/blob/main/docs/python.md){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   [Node.js API Reference](https://github.com/firecrawl/pdf-inspector/blob/main/napi/README.md){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   [Browser WebAssembly API Reference](https://github.com/firecrawl/pdf-inspector/blob/main/wasm/README.md){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   [Rust API Reference](https://github.com/firecrawl/pdf-inspector/blob/main/docs/rust-api.md){:target=\"_blank\" rel=\"noopener noreferrer\"}\n\n## Examples\n\nHere are quick examples demonstrating how to use `pdf-inspector` for common tasks.\n\n### Python\n\npython\nimport pdf_inspector\n\nresult = pdf_inspector.process_pdf(\"document.pdf\")\nprint(result.pdf_type)   # \"text_based\", \"scanned\", \"image_based\", \"mixed\"\nprint(result.markdown)   # Markdown string or None\n\n# Selective OCR; clean text PDFs do not load the external OCR runtime.\nocr = pdf_inspector.process_pdf_with_ocr(\"document.pdf\")\nprint(ocr.pages_routed_to_ocr)\n\n\n### Node.js\n\njavascript\nimport { readFileSync } from 'fs';\nimport { processPdf, processPdfWithOcr } from '@firecrawl/pdf-inspector';\n\nconst pdf = readFileSync('document.pdf');\nconst result = processPdf(pdf);\nconsole.log(result.pdfType);   // \"TextBased\", \"Scanned\", \"ImageBased\", \"Mixed\"\nconsole.log(result.markdown);  // Markdown string or null\n\nconst ocr = await processPdfWithOcr(pdf); // selective OCR, off the event loop\nconsole.log(ocr.pagesRoutedToOcr);\n\n\n### Browser WebAssembly\n\njavascript\nimport init, { processPdf } from '@firecrawl/pdf-inspector-wasm';\n\nawait init();\nconst response = await fetch('/document.pdf');\nconst pdf = new Uint8Array(await response.arrayBuffer());\nconst result = processPdf(pdf);\n\nconsole.log(result.pdfType);\nconsole.log(result.markdown);\n\n\n### Rust\n\nrust\nuse pdf_inspector::process_pdf;\n\nlet result = process_pdf(\"document.pdf\")?;\nprintln!(\"Type: {:?}\", result.pdf_type);\nif let Some(markdown) = &result.markdown {\n    println!(\"{}\", markdown);\n}\n\n\n### CLI\n\nbash\n# Convert PDF to Markdown\npdf2md document.pdf\n\n# JSON output (for piping)\npdf2md document.pdf --json\n\n# Detection only (no extraction)\ndetect-pdf document.pdf\n\n\n## Why Use `pdf-inspector`?\n\n`pdf-inspector` stands out for its unique combination of speed, accuracy, and versatility, making it an ideal choice for various PDF processing needs.\n\n*   **Intelligent PDF Classification:** It quickly identifies PDF types (TextBased, Scanned, ImageBased, Mixed) with high confidence, allowing for efficient routing. This smart classification saves significant costs and latency by avoiding unnecessary OCR for text-based documents.\n*   **High-Fidelity Text Extraction:** The library performs position-aware text extraction, capturing font information, X/Y coordinates, and automatically handling multi-column reading order. This ensures accurate and structured text output.\n*   **Comprehensive Markdown Conversion:** `pdf-inspector` excels at converting complex PDF layouts into clean Markdown. It intelligently detects and formats headings (H1-H4), various list types, code blocks, tables (both rectangle-based and heuristic), bold/italic text, and URLs, providing a highly readable output.\n*   **Multi-Platform Accessibility:** With robust bindings for Python, Node.js, and browser WebAssembly, alongside a powerful Rust API and CLI tools, `pdf-inspector` integrates seamlessly into diverse development workflows.\n*   **Exceptional Performance:** Benchmarks demonstrate `pdf-inspector`'s superior performance in overall score, reading order, table detection, and processing speed compared to other local PDF parsers. It processes 200 documents in under half a second, making it incredibly fast.\n*   **Cost and Latency Savings:** By accurately identifying text-based PDFs, `pdf-inspector` allows developers to process a majority of documents locally and quickly, bypassing the need for expensive and time-consuming external OCR services. This is particularly beneficial for reports, research papers, financial documents, and legal PDFs.\n\n## Links\n\n*   **GitHub Repository:** [https://github.com/firecrawl/pdf-inspector](https://github.com/firecrawl/pdf-inspector){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   **Crates.io:** [https://crates.io/crates/pdf-inspector](https://crates.io/crates/pdf-inspector){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   **npm Package:** [https://www.npmjs.com/package/@firecrawl/pdf-inspector](https://www.npmjs.com/package/@firecrawl/pdf-inspector){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   **PyPI Package:** [https://pypi.org/project/pdf-inspector/](https://pypi.org/project/pdf-inspector/){:target=\"_blank\" rel=\"noopener noreferrer\"}\n*   **License (MIT):** [https://github.com/firecrawl/pdf-inspector/blob/main/LICENSE](https://github.com/firecrawl/pdf-inspector/blob/main/LICENSE){:target=\"_blank\" rel=\"noopener noreferrer\"}","metrics":{"detailViews":2,"githubClicks":0},"dates":{"published":null,"modified":"2026-08-26T11:17:03.000Z"}}