Skip to main content

Page-wise PDF to Markdown extraction with text extraction, OCR, LLM fallback, and progress metadata.

Project description

pagewise-pdf-extractor

Page-wise PDF to Markdown extraction with text extraction, OCR, LLM fallback, and progress metadata.

pagewise-pdf-extractor is a Python package and CLI for converting PDFs into deterministic page-level Markdown files. It routes each page through embedded-text extraction, scanned-page OCR, and optional vision-model fallback, then returns structured results for RAG and document-processing pipelines.

What It Does

  • Extracts text-native PDF pages with PyMuPDF.
  • Extracts scanned/image pages with Marker.
  • Falls back to Ollama vision OCR when configured OCR fails.
  • Writes one UTF-8 Markdown file per page.
  • Writes atomic progress.json with provider attempts, status, config hash, source hash, and page metadata.
  • Exposes a library API for applications and a CLI for operators.
  • Keeps local processing as the default; remote services are only used if explicitly configured.

Status

v0.2.0 is the current public release. The public API is intended for early downstream use by applications that need page-wise PDF extraction, but the project is still pre-1.0.

Install

From PyPI after publication:

python -m pip install pagewise-pdf-extractor

Pinned Git dependency:

pagewise-pdf-extractor @ git+https://github.com/ebmurha/pagewise-pdf-extractor.git@v0.2.0

Local development:

python -m pip install -e D:\Developer\Projects\pagewise-pdf-extractor

Runtime dependencies are declared in pyproject.toml. OCR providers also require local binaries:

  • marker_single for Marker OCR
  • ollama for Ollama fallback
  • pdftoppm for rendering pages passed to Ollama

Check the local environment:

pagewise-pdf-extractor --validate-environment

Quickstart

CLI:

pagewise-pdf-extractor document.pdf --output-root output

Python:

from pathlib import Path

from pagewise_pdf_extractor import ExtractionConfig, process_pdf, validate_environment

config = ExtractionConfig(
    text_provider="pymupdf",
    ocr_provider="marker",
    fallback_provider="ollama",
    fallback_enabled=True,
    ollama_model="deepseek-ocr",
)

report = validate_environment(config)
if report.has_fatal_errors:
    raise RuntimeError(report.summary)

result = process_pdf(
    input_pdf=Path("document.pdf"),
    output_root=Path("output"),
    config=config,
)

Public import contract:

from pagewise_pdf_extractor import (
    ExtractionConfig,
    ExtractionResult,
    process_pdf,
    validate_environment,
)

Output

Default layout:

output/
  <input_sha256>/
    page_0001.md
    page_0002.md
    progress.json

Successful page:

# Page N

<provider markdown content>

Failed page:

# Page N

OCR FAILED

Error: <error_message>

Provider Routing

Default page-level routing:

  1. Try embedded text extraction with PyMuPDF.
  2. Accept embedded text when it meets configured quality thresholds.
  3. Use Marker OCR when embedded text is absent, low quality, or force_ocr=True.
  4. Use Ollama fallback when Marker fails or returns unusable output and fallback is enabled.
  5. Write failure Markdown if all configured providers fail.

Documentation

Tests

python -m unittest discover -s tests -p "test_*.py"
python -c "from pagewise_pdf_extractor import ExtractionConfig, process_pdf, validate_environment; print('ok')"
pagewise-pdf-extractor --help

Future Goals

Future work should preserve the public API, keep provider behavior explicit, and add new providers or extraction quality improvements behind documented configuration.

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

pagewise_pdf_extractor-0.2.0.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

pagewise_pdf_extractor-0.2.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file pagewise_pdf_extractor-0.2.0.tar.gz.

File metadata

  • Download URL: pagewise_pdf_extractor-0.2.0.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pagewise_pdf_extractor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 33ae789b57a7bd4e6f7ce3b4f55c1409fa7f3e00af777c30b5e76c3fb3651301
MD5 2c9cd4bc489e00a8c164fcfbcbd3e853
BLAKE2b-256 33abc96c7e235ae71205417759a0a1b3bb89634729d7cc7c5a41f4d07e89c7ab

See more details on using hashes here.

File details

Details for the file pagewise_pdf_extractor-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pagewise_pdf_extractor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ef3a34142c4c995cda4dc0adb96125df7512b0305a65fa57a1bafa7bec3ac75
MD5 db21b149b71725601329a9ebfa6d94bf
BLAKE2b-256 5092d7eab52a9fd5b78bc2ab9dacff790b4d605a23ef1ea44ea7a84eb5ef14ea

See more details on using hashes here.

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