Skip to main content

PDF OCR Tool

Convert scanned or poorly OCR'd PDFs into searchable PDFs with selectable text using Tesseract OCR.

Features

  • 🎯 High-quality OCR using Tesseract 5.x
  • 📄 Creates searchable PDFs with invisible text layer
  • 🎨 Interactive, user-friendly command-line interface
  • ⚡ Fast processing with configurable DPI (default: 300)
  • 🎭 Process entire PDFs or specific page ranges

Prerequisites

Install system dependencies first:

macOS:

brew install tesseract poppler

Linux (Ubuntu/Debian):

sudo apt-get install tesseract-ocr poppler-utils

Quick Start

Option 1: Run Directly from GitHub (Easiest - No Installation!)

uvx --from git+https://github.com/sameerbajaj/pdf-ocr pdf-ocr

That's it! The tool will run directly without any installation.

Option 2: Clone and Run Locally

# Clone the repository
git clone https://github.com/sameerbajaj/pdf-ocr.git
cd pdf-ocr

# Run directly
uvx --from . pdf-ocr

Option 3: Install Permanently

# Clone and install
git clone https://github.com/sameerbajaj/pdf-ocr.git
cd pdf-ocr
uv pip install -e .
source .venv/bin/activate

# Run from anywhere
pdf-ocr

Usage

Simply run the command and follow the friendly prompts:

pdf-ocr

The tool will ask you:

  1. Which PDF file? - You can type the path or drag & drop the file
  2. Which pages? - Enter a range like 4-5, a single page like 7, or press Enter for all pages

Command-Line Mode

# Process entire PDF
pdf-ocr document.pdf

# Process specific pages
pdf-ocr document.pdf --pages 4-5
pdf-ocr document.pdf -p 1-10

# Custom output
pdf-ocr document.pdf --output result.pdf

# Save text files too
pdf-ocr document.pdf --save-text

# Higher quality (slower)
pdf-ocr document.pdf --dpi 400

Examples

# Process pages 4-5 of a book
pdf-ocr book.pdf --pages 4-5

# Process chapter (pages 20-40) with text export
pdf-ocr textbook.pdf -p 20-40 --save-text

# High-quality scan of a single page
pdf-ocr scan.pdf --pages 7 --dpi 600

Output

The tool generates:

  • filename_ocr.pdf or filename_pages4-5_ocr.pdf - Searchable PDF with text layer
  • filename_pageX.txt (optional) - Plain text files if --save-text is used

All files are saved in the same directory as the input PDF.

Troubleshooting

Command not found:

source .venv/bin/activate

Tesseract not installed:

brew install tesseract  # macOS
sudo apt-get install tesseract-ocr  # Linux

Poppler not installed:

brew install poppler  # macOS
sudo apt-get install poppler-utils  # Linux

Development

# Setup for development
git clone https://github.com/yourusername/pdf-ocr-tool.git
cd pdf-ocr-tool
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"

# Run from source
python -m pdf_ocr_tool.cli

Project Structure

pdf-ocr-tool/
├── pdf_ocr_tool/          # Main package
│   ├── cli.py            # Command-line interface
│   ├── ocr.py            # OCR processing
│   └── pdf_utils.py      # PDF generation
├── pyproject.toml        # Package configuration
├── setup.sh              # Auto-installer script
└── README.md             # This file

License

MIT License - see LICENSE file for details.

Acknowledgments


Part of the open-source tools collection by Sameer Bajaj. Learn more on the project page.

Metadata

Release files for pdf-ocr-cli 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdf-ocr-cli 1.0.0
File Size Uploaded Provenance Actions
pdf_ocr_cli-1.0.0.tar.gz 9.9 kB Without provenance Details for pdf_ocr_cli-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdf-ocr-cli 1.0.0
File Interpreter ABI Platform Actions
pdf_ocr_cli-1.0.0-py3-none-any.whl Python 3 none any Details for pdf_ocr_cli-1.0.0-py3-none-any.whl

Total release size: 21.1 kB

Release files / pdf_ocr_cli-1.0.0.tar.gz

Download URL pdf_ocr_cli-1.0.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21c29d7e2501e90496af2082137cb8157acc259fcc0622b1c4510ff18f0ca062
BLAKE2b-256 checksum
How to use checksums
2dd892468122e10db2f75fb41d45d97cd6b579aa1b5e070f951cd93be8e5ddf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / pdf_ocr_cli-1.0.0-py3-none-any.whl

Download URL pdf_ocr_cli-1.0.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfebf8a8810d5a29e6b3b19cea6a682fd7b5ff2c1d8382d977c48b3576670e80
BLAKE2b-256 checksum
How to use checksums
597e853ef279e3c396e852dc11e61e976a83e11bd3602444109a99abab48f8f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Security for pdf-ocr-cli 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page