Skip to main content

Fast PDF inspection, classification, and text extraction with smart scanned vs text-based detection

Project description

pdf-inspector

Fast PDF classification and text extraction. Detects whether a PDF is text-based or scanned, extracts text with position awareness, and converts to clean Markdown — all without OCR. Python bindings via PyO3 for the pdf-inspector Rust library.

Built by Firecrawl to handle text-based PDFs locally in under 200ms, skipping expensive OCR services for the ~54% of PDFs that don't need them.

Install

pip install pdf-inspector

Prebuilt wheels cover CPython ≥3.8 on Linux (x86_64, aarch64), macOS (Intel, Apple Silicon), and Windows (x64). Other platforms build from source, which requires a Rust toolchain. For local development in a repo checkout:

pip install maturin
maturin develop --release

Usage

import pdf_inspector

# Full processing: detect + extract + convert to Markdown
result = pdf_inspector.process_pdf("document.pdf")
print(result.pdf_type)      # "text_based", "scanned", "image_based", "mixed"
print(result.confidence)     # 0.0 - 1.0
print(result.page_count)     # number of pages
print(result.markdown)       # Markdown string or None

# Process specific pages only
result = pdf_inspector.process_pdf("document.pdf", pages=[1, 3, 5])

# Process from bytes (no filesystem needed)
with open("document.pdf", "rb") as f:
    result = pdf_inspector.process_pdf_bytes(f.read())

# Fast detection only (no text extraction)
result = pdf_inspector.detect_pdf("document.pdf")
if result.pdf_type == "text_based":
    print("Can extract locally!")
else:
    print(f"Pages needing OCR: {result.pages_needing_ocr}")

# Plain text extraction
text = pdf_inspector.extract_text("document.pdf")

# Positioned text items with font info
items = pdf_inspector.extract_text_with_positions("document.pdf")
for item in items[:5]:
    print(f"'{item.text}' at ({item.x:.0f}, {item.y:.0f}) size={item.font_size}")

# Per-page markdown (one Markdown string per page, plus layout metadata)
result = pdf_inspector.extract_pages_markdown("document.pdf")
for page in result.pages:
    print(f"Page {page.page}: {len(page.markdown)} chars, needs_ocr={page.needs_ocr}")

# Restrict to specific 0-indexed pages (preserves caller order)
result = pdf_inspector.extract_pages_markdown("document.pdf", pages=[0, 2])

API reference

Function Description
process_pdf(path, pages=None) Full processing (detect + extract + markdown)
process_pdf_bytes(data, pages=None) Full processing from bytes
detect_pdf(path) Fast detection only (returns PdfResult)
detect_pdf_bytes(data) Fast detection from bytes
classify_pdf(path) Lightweight classification (returns PdfClassification)
classify_pdf_bytes(data) Lightweight classification from bytes
extract_text(path) Plain text extraction
extract_text_bytes(data) Plain text extraction from bytes
extract_text_with_positions(path, pages=None) Text with X/Y coords and font info
extract_text_with_positions_bytes(data, pages=None) Text with positions from bytes
extract_text_in_regions(path, page_regions) Extract text in bounding-box regions
extract_text_in_regions_bytes(data, page_regions) Region extraction from bytes
extract_pages_markdown(path, pages=None) Per-page Markdown + layout metadata (all pages by default)
extract_pages_markdown_bytes(data, pages=None) Per-page Markdown from bytes

Types

PdfResult fields: pdf_type, markdown, page_count, processing_time_ms, pages_needing_ocr, title, confidence, is_complex_layout, pages_with_tables, pages_with_columns, has_encoding_issues

PdfClassification fields: pdf_type, page_count, pages_needing_ocr (0-indexed), confidence

TextItem fields: text, x, y, width, height, font, font_size, page, is_bold, is_italic, item_type

RegionText fields: text, needs_ocr

PageRegionTexts fields: page (0-indexed), regions (list of RegionText)

PageMarkdown fields: page (0-indexed), markdown, needs_ocr

PagesExtractionResult fields: pages (list of PageMarkdown), pages_with_tables (1-indexed), pages_with_columns (1-indexed), pages_needing_ocr (1-indexed), is_complex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_inspector-0.2.2.tar.gz (10.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pdf_inspector-0.2.2-cp38-abi3-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

pdf_inspector-0.2.2-cp38-abi3-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pdf_inspector-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file pdf_inspector-0.2.2.tar.gz.

File metadata

  • Download URL: pdf_inspector-0.2.2.tar.gz
  • Upload date:
  • Size: 10.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pdf_inspector-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0cc31bd90b14215882bab3e19c9dd8a2eb3770478941757434eff3ebdfaf9272
MD5 4c01395fe9947c7c69a6dfa2a0c2f6f6
BLAKE2b-256 c4149ebfccf9a03a8608770ecf9fada85d4ec2ba829041a1ed4fd61e1a4e1ec6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2.tar.gz:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdf_inspector-0.2.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pdf_inspector-0.2.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 73d830859cce3437c57c6eb4d2157d8026bf97857cf5434f11bfb07cdab052f5
MD5 00712db9832319dbfdbd0ccaf930d961
BLAKE2b-256 b685418e41d435cafde44f911f0d3d4e2071ae95d2c2fb94118328aa782245b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2-cp38-abi3-win_amd64.whl:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 36d4a3500893c785bafbfbf0b29eab37e1f7eea2acea7b625be72ec08ea65617
MD5 f4cab70d6c3685ad5d877859655d77da
BLAKE2b-256 ce0f322079cb979a69b3cdc7c12a0103ae33d192df405d6f91fbca9f8126dffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0d497fc977bc5abe22ca35d32f116475094ed85592f03c59454faf41b99beab7
MD5 264aae32d8e2e85966f2b4bb19c2b9ad
BLAKE2b-256 288511465dc8dd4f0310e12231fe2a09f75bf0d01e308466861a3ef86b11da12

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdf_inspector-0.2.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pdf_inspector-0.2.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a1a51c56579b4f90cfe0b3da980323abcb8b6d2c06fb3a53ce20e7882789557
MD5 d258936346229d6f240c8e997daa9b4b
BLAKE2b-256 8e9e7a9b7a32507afab071a6cc5ccb38717ee793c8c95497af5acc40a31e7ed5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdf_inspector-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pdf_inspector-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4366f0ee00510ca520e842185effe8bf5a3b0b6c9e92472c379c9479e3b41a7f
MD5 8694ad5f3f283cd0c616a4db85529d1e
BLAKE2b-256 9f7f6d2ce489f0476dc82b8978e947c9e81d2d0629d5864724bdc64bd435c7bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_inspector-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-pypi.yml on firecrawl/pdf-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page