pdf-inspector: A fast Rust classifier that decides when OCR is actually needed
GitHub describes it as Fast Rust library for PDF inspection, classification, and text extraction. Intelligently detects scanned vs text-based PDFs to enable smart routing decisions.. The repository metadata lists Rust as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.
At a glance
- What is it?
- Firecrawl's pdf-inspector classifies PDFs as text-based, scanned, image-based, or mixed in milliseconds, extracts positioned text and Markdown, and routes only the pages that need it to OCR. The benchmark table and API bindings show a serious local-first tool, but the selective OCR path carries external dependencies you should verify before adopting it.
- Who is it for?
- Adopt pdf-inspector if you process many native-text PDFs locally and want fast classification plus structured Markdown without paying for OCR on every file. Skip it if your corpus is mostly scanned or image-heavy, because the default build returns no text and the OCR path requires external PDFium and ONNX Runtime models.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.
Star history
- firecrawl/pdf-inspector20,098 ★ · +4,835
| Repository | 2026-08-13 | 2026-11-23 |
|---|---|---|
| firecrawl/pdf-inspector | 15.3k | 20.1k |
4,835 Stars in the last 102 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The problem: OCR is wasted on most PDFs
Firecrawl built pdf-inspector to solve a cost problem. Their claim is that roughly 54% of PDFs are text-based and do not need OCR at all. Sending those documents to an OCR service burns money and latency. The library's job is to look at a PDF, decide whether it is text-based, scanned, image-based, or mixed, and only then route pages to OCR when necessary. That decision is the core value. The target user is a developer or pipeline operator who processes invoices, reports, research papers, or legal documents in bulk and wants to avoid paying for OCR on files that already contain extractable text. The library is positioned as a local default: parse the PDF on your own machine, under 200ms for text-based files, and skip the external OCR service entirely.
How classification actually works
The README describes classification as sampling content streams and returning a confidence score between 0.0 and 1.0. It runs in roughly 10-50ms per document. The output is one of four types: TextBased, Scanned, ImageBased, or Mixed. The library also returns per-page OCR routing, which means the classifier does not just label the whole document. It can tell you which specific pages need OCR. That granularity matters for mixed PDFs, where a 100-page report might have 95 text pages and 5 scanned inserts. The document is parsed once and shared between detection and extraction, which avoids redundant I/O. The classification step is cheap enough to run before any extraction, which is the design that makes selective OCR possible.
Text extraction and Markdown conversion details
Beyond classification, pdf-inspector extracts text with position awareness. It records X/Y coordinates and font information for each text item. That positional data feeds into several features: multi-column reading order, heading detection via font size ratios, table detection, and list formatting. The Markdown converter handles H1-H4 headings, bullet and numbered lists, code blocks from monospace font detection, tables from both rectangle-based drawing ops and text alignment heuristics, bold and italic formatting, URL linking, and page breaks. It also supports CID fonts through ToUnicode CMap decoding for Type0 and Identity-H fonts, covering UTF-16BE, UTF-8, and Latin-1 encodings. The library flags broken font encodings so callers can fall back to OCR. That is a practical safety valve, because malformed PDFs are common in the wild.
The selective OCR path and its external dependencies
The headline addition is selective OCR. The Rust, CLI, Python, and Node builds can render only the pages that need OCR, run PP-OCRv6 Small locally, and preserve per-page provenance. The critical detail is that the default Rust and browser builds remain pure extraction. Native Python and Node packages include the OCR integration, but PDFium, ONNX Runtime, and model files stay external and are only touched when a page is routed to OCR. That means the OCR path is not self-contained. You need to install and manage PDFium and the ONNX Runtime separately. Native Rust and CLI consumers opt into selective OCR, and docs/rust-api.md is the full Rust API reference.
Benchmark results and what they actually show
The README includes a benchmark on the opendataloader-bench corpus of 200 PDFs. The comparison is limited to local engines without model-based PDF parsing, and OCR was disabled. pdf-inspector scored 0.875 overall, 0.915 on reading order, 0.814 on tables, and 0.788 on headings. It completed the 200 documents in 0.470 seconds. The closest competitor, liteparse, scored 0.873 overall and 0.811 on headings, but took 0.750 seconds. PyMuPDF4LLM scored 0.735 overall and took 17.117 seconds. MarkItDown scored 0.589 overall and took 16.165 seconds. These numbers are from a single machine, an Apple M4 Pro, with specific engine versions. The results were refreshed on July 31, 2026. The README points to a reproducible results branch with the full configuration and per-document predictions. That is a useful transparency measure. The headline finding is that pdf-inspector leads on overall, reading order, and table scores while being fastest. But the heading score of 0.788 is lower than liteparse's 0.811, so it is not dominant everywhere.
Getting started across four language bindings
The quick start shows four ways to use the library. In Python, you pip install pdf-inspector and call process_pdf, which returns a result with pdf_type and markdown fields. For OCR, process_pdf_with_ocr returns pages_routed_to_ocr. In Node.js, you npm install @firecrawl/pdf-inspector and call processPdf or processPdfWithOcr. The browser WebAssembly package is @firecrawl/pdf-inspector-wasm, and the example shows an async init call before processing. In Rust, you add pdf-inspector = "1" to Cargo.toml and call process_pdf. The CLI is installed via cargo install pdf-inspector and provides pdf2md with flags for JSON output with document information, positioned TextItem JSON, and raw markdown. For the OCR opt-in, consult docs/rust-api.md.
Limitations and when this is the wrong tool
The most obvious limitation is that the default build does no OCR. If your PDFs are scanned or image-based, the result markdown will be null. The library will classify them correctly, but it will not give you text unless you enable the OCR path, which requires external PDFium and ONNX Runtime. That is a significant setup burden. The benchmark also has a narrow scope: it only covers local engines without model-based parsing, and OCR was disabled. If your workload includes complex layouts or heavily damaged PDFs, the benchmark does not guarantee similar results. The library also assumes you want Markdown output. If you need raw text with exact font styling or precise coordinates for every glyph, the --items-json flag provides positioned TextItem data, but the default extraction is oriented toward structured Markdown. For a document with unusual column layouts or non-standard fonts, the heuristic reading order and table detection may fail silently.
Alternatives and how they differ
The benchmark names three direct alternatives. PyMuPDF4LLM is the most established one: it wraps PyMuPDF and produces Markdown, but it scored lower on reading order and tables and took 17 seconds for the same corpus. The key difference is that PyMuPDF4LLM is a Python library with a large dependency tree, while pdf-inspector is a Rust core with bindings. liteparse is the closest competitor on quality, scoring nearly the same overall but slower and better on headings. The difference in approach is that liteparse appears to be a separate parser with its own heuristics, while pdf-inspector focuses on classification plus selective OCR. OpenDataLoader is another local parser, but it scored lower on tables and was much slower. If you need OCR on every page, none of these are direct replacements, because the benchmark disabled OCR. A tool like Tesseract or a cloud OCR service would be the alternative for fully scanned corpora, but that is a different cost model.
Maintenance, licensing, and upgrade considerations
The project is MIT licensed, which is permissive and fits most commercial use. The repository is actively maintained, with releases v1.25.0, v1.25.1 and v1.25.2 all published on September 28, 2026. Cargo.toml and pyproject.toml both carry version 1.25.2, and pyproject.toml notes that package versions are kept in sync. The external dependencies for OCR are a maintenance burden: you must keep PDFium and ONNX Runtime versions in sync with the library's expectations. The repository carries a CHANGELOG.md. For a production pipeline, you should pin the exact version of the Python or Node package and test the OCR path after each upgrade.
Editorial conclusion
Adopt pdf-inspector if you process many native-text PDFs locally and want fast classification plus structured Markdown without paying for OCR on every file. Skip it if your corpus is mostly scanned or image-heavy, because the default build returns no text and the OCR path requires external PDFium and ONNX Runtime models. Before committing, verify the benchmark corpus matches your document mix, test the selective OCR on a sample of your worst PDFs, and confirm the Python or Node package includes the OCR integration you expect, since the Rust and browser builds stay pure extraction by default.
Frequently asked questions
Is there a way to inspect a PDF?
With pdf-inspector, yes. It classifies a document as TextBased, Scanned, ImageBased or Mixed with a confidence score, extracts positioned text with font information and coordinates, and converts to Markdown. The CLI can also emit positioned TextItem JSON through the --items-json flag.
What are the signs of a PDF virus?
The library makes no claims about malicious files, but it does expose document metadata you can look at. The --json output of the pdf2md command includes the document information, among them title, author, producer and dates, and --items-json exposes paint details, meaning fill and stroke colour and render mode, for each text item.
How to make a PDF unreadable?
pdf-inspector cannot do that, since it only reads PDFs and writes Markdown or JSON. Its outputs are a Markdown string, JSON document information, positioned TextItem JSON, and raw Markdown with no headers. Making a PDF unreadable would require a writer, which is outside what this project does.
How to download a PDF using Inspect?
Nothing here downloads a PDF from a web page. Every entry point takes a file you already have: process_pdf("document.pdf") in Python, readFileSync followed by processPdf in Node, and in the browser package a fetch of the file followed by processPdf on the resulting buffer.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/firecrawl-pdf-inspector)Star history chart for your README
[](https://hysenlabs.com/projects/firecrawl-pdf-inspector)Was this useful?