Skip to main content

A Python library and CLI tool that uses LLMs to enhance PDF files

Project description

pdfalive logo


CI GitHub License PyPI - Version PyPI - Python Version

A Python library and CLI toolkit that brings PDF files alive with the power of LLMs.

Highlights

  • 📑 Automatic TOC Generation — Generate clickable Table of Contents (PDF bookmarks) using LLM inference. Supports arbitrarily large documents with intelligent batching.
  • 🔍 Smart OCR Detection — Automatically detects scanned PDFs and performs OCR via Tesseract when needed.
  • 📝 Intelligent File Renaming — Batch rename files using natural language instructions with LLM-powered inference.
  • 🤖 Multi-Provider LLM Support — Use any LLM provider via LangChain: OpenAI, Anthropic, local models via Ollama, and more.
  • 🔄 Built-in Resilience — Automatic retry logic with exponential backoff for handling API rate limits.

Installation

Tesseract is required for OCR functionality. On macOS:

brew install tesseract

Install pdfalive via pip:

pip install pdfalive

Or run directly without installation using uvx:

uvx pdfalive generate-toc input.pdf output.pdf

Usage

Use --help on any command for detailed options:

pdfalive --help
pdfalive generate-toc --help

generate-toc

Generate a clickable Table of Contents using PDF bookmarks. The tool extracts font and text features from the PDF and uses an LLM to intelligently identify chapter and section headings.

pdfalive generate-toc input.pdf output.pdf

# Or modify the file in place
pdfalive generate-toc --inplace input.pdf

Choosing an LLM:

By default, pdfalive uses the latest OpenAI model. Use any LangChain-supported model:

# Use Claude
pdfalive generate-toc --model-identifier 'claude-sonnet-4-5' input.pdf output.pdf

# Use a local model via Ollama
pdfalive generate-toc --model-identifier 'ollama/llama3' input.pdf output.pdf

Set the appropriate API key for your provider (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.).

Scanned PDFs:

OCR is enabled by default. Scanned documents without extractable text are automatically detected and processed:

# Default: OCR text layer discarded after TOC generation (preserves file size)
pdfalive generate-toc scanned.pdf output.pdf

# Include OCR text layer in output (makes PDF searchable)
pdfalive generate-toc --ocr-output scanned.pdf output.pdf

# Disable automatic OCR entirely
pdfalive generate-toc --no-ocr input.pdf output.pdf

Postprocessing:

For documents with a printed table of contents page, enable LLM postprocessing to refine results:

pdfalive generate-toc --postprocess input.pdf output.pdf

Postprocessing uses an additional LLM call to:

  • Remove duplicate entries and fix typos
  • Cross-reference against any printed TOC found in the document
  • Add missing entries and correct page numbers

Other options:

Option Description
--inplace Modify the input file in place instead of creating a new output file
--force Overwrite existing TOC if the PDF already has bookmarks
--ocr-language Set OCR language (default: eng). Use Tesseract language codes
--request-delay Delay between LLM calls for rate limiting (default: 2s)

extract-text

Extract text from scanned PDFs using OCR and save to a new PDF with an embedded text layer:

pdfalive extract-text input.pdf output.pdf

# Or modify the file in place
pdfalive extract-text --inplace input.pdf

This creates a searchable/selectable PDF without generating a TOC.

Options:

Option Description
--inplace Modify the input file in place instead of creating a new output file
--force Force OCR even if document already has text
--ocr-language Set OCR language (default: eng)
--ocr-dpi DPI resolution for OCR processing (default: 300)

rename

Intelligently rename files using LLM inference. Analyzes filenames and applies renaming rules based on natural language instructions.

pdfalive rename -q "Add 'REVIEWED_' prefix" *.pdf

Custom naming formats:

Specify exact formatting including special characters — the LLM respects brackets, parentheses, dashes, and other formatting:

pdfalive rename -q "[Author Last Name] - Title (Year).pdf" paper1.pdf paper2.pdf

Workflow:

  1. The tool analyzes each filename and generates rename suggestions
  2. A preview table shows original names, proposed names, confidence scores, and reasoning
  3. Confirm or cancel the operation (unless -y is used)
  4. Files are renamed in place

Automatic confirmation:

pdfalive rename -q "Add sequential numbering prefix" -y *.pdf

Options:

Option Description
--model-identifier Choose which LLM to use (default: gpt-5.1)
-y, --yes Automatically apply renames without confirmation
--show-token-usage Display token usage statistics (default: enabled)

Development

We use uv to manage the project:

# Install dependencies
uv sync

# Install in editable mode
uv pip install -e .

Code quality tools:

Tool Purpose
ruff Formatting and linting
mypy Static type checking
pytest Unit testing
pre-commit Git hooks for quality checks
# Run linting
uv run ruff check .
uv run ruff format .

# Run type checking
uv run mypy pdfalive

# Run tests
uv run pytest

License

pdfalive is distributed under the terms of the MIT License.

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

pdfalive-0.7.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

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

pdfalive-0.7.0-py3-none-any.whl (160.3 kB view details)

Uploaded Python 3

File details

Details for the file pdfalive-0.7.0.tar.gz.

File metadata

  • Download URL: pdfalive-0.7.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pdfalive-0.7.0.tar.gz
Algorithm Hash digest
SHA256 487313003b2682a28d3127b2c69d57f79160422629a6a5c4ad4292f0cc4fa2fc
MD5 dd77ec73da542b6ecc31b1e691cd3c62
BLAKE2b-256 392f88cda19b21bc1ad5cc2ebaff2d8ff5565bb628be58c408b7d58ceea9292e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfalive-0.7.0.tar.gz:

Publisher: publish-to-pypi.yml on promptromp/pdfalive

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

File details

Details for the file pdfalive-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: pdfalive-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 160.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pdfalive-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c80d3272a793628a98cdc072d65fd760b0e1242c05954f62da48b425ab46950
MD5 fc3d386aeec625cbe37eb2d961b9eadd
BLAKE2b-256 0ac58baf85b7220e481427220e26533e2d9fb850b5b9d88f0db66e8f4c094ab7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfalive-0.7.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on promptromp/pdfalive

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