Skip to main content

PDF2EPUB 📚

PyPI version CI/CD Pipeline Python 3.9+ License: MIT

A powerful Python package for converting PDF files to EPUB format via Markdown with intelligent layout detection, AI-powered postprocessing, and seamless CLI/API integration.

✨ Features

  • 📖 Smart Layout Detection - Handles books, academic papers, and complex documents
  • 🔍 Advanced PDF Processing - OCR, table detection, and image extraction
  • 🤖 AI Postprocessing - Enhance quality with Anthropic Claude integration
  • 📝 Clean Markdown Output - Structured, readable markdown with preserved formatting
  • 📱 Professional EPUB - High-quality EPUB 3.0 output with customizable styling
  • 🌍 Multi-language Support - Process documents in multiple languages
  • 🚀 GPU Acceleration - NVIDIA CUDA and AMD ROCm support for faster processing
  • 🍎 Apple Silicon Support - Optimized performance on Apple Silicon devices
  • 🛠️ Flexible API - Use as CLI tool or import as Python library
  • 🔌 Plugin Architecture - Extensible AI provider system

🚀 Quick Start

Installation

# Basic installation
pip install pdf2epub

# Full installation with all features
pip install pdf2epub[full]

Command Line Usage

# Convert a PDF to EPUB
pdf2epub document.pdf

# Advanced options
pdf2epub book.pdf --start-page 10 --max-pages 50 --langs "English,German"

Python API

  • For Apple Silicon, install with MPS support:
pip3 uninstall torch torchvision torchaudio
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
  • For Apple Silicon, install with MPS support:
pip3 uninstall torch torchvision torchaudio
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
  1. Verify GPU support:
import torch
print(torch.__version__)  # PyTorch version
print(torch.cuda.is_available())  # Should return True for NVIDIA
print(torch.mps.is_available())  # Should return True for Apple Silicon
print(torch.version.hip)  # Should print ROCm version for AMD

import pdf2epub

# Simple conversion
pdf2epub.convert_pdf_to_markdown("document.pdf", "output/")
pdf2epub.convert_markdown_to_epub("output/", "final/")

# Advanced usage with AI enhancement
processor = pdf2epub.AIPostprocessor("output/")
processor.run_postprocessing("document.md", "anthropic")

📦 Installation Options

Basic Installation

pip install pdf2epub

Includes core functionality with minimal dependencies.

Full Installation

pip install pdf2epub[full]

Includes all features: PDF processing, AI postprocessing, and GPU acceleration.

Development Installation

pip install pdf2epub[dev]

Includes development tools: testing, linting, and formatting.

GPU Support

NVIDIA CUDA:

pip install pdf2epub[full]
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

AMD ROCm:

pip install pdf2epub[full]
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2

📚 Documentation

🎯 Use Cases

Academic Research

  • Convert research papers to readable EPUB format
  • Extract and preserve mathematical equations
  • Maintain citation formatting and structure

Digital Publishing

  • Transform print-ready PDFs into distribution-ready EPUBs
  • Preserve complex layouts and formatting
  • Optimize for e-reader compatibility

Document Archival

  • Convert legacy documents to modern formats
  • Batch process document collections
  • Enhance readability with AI postprocessing

Accessibility

  • Create screen-reader compatible versions
  • Improve text structure and navigation
  • Add semantic markup for better accessibility

🔧 Configuration

Environment Variables

# Required for AI postprocessing
export ANTHROPIC_API_KEY="your-anthropic-api-key"

# Optional: Control GPU usage
export CUDA_VISIBLE_DEVICES="0"  # Use specific GPU
export CUDA_VISIBLE_DEVICES=""   # Force CPU-only mode

API Configuration

import pdf2epub

# Configure default settings
pdf2epub.config.set_default_batch_multiplier(3)
pdf2epub.config.set_default_ai_provider("anthropic")

🧪 Testing

Run the test suite:

pytest                    # Run all tests
pytest --cov=pdf2epub   # Run with coverage
pytest tests/test_pdf2md.py  # Run specific test file

Current test coverage: 49% with 100% pass rate (41/41 tests)

🔌 Plugin System

Create custom AI postprocessing providers:

from pdf2epub.postprocessing.ai import AIPostprocessor

class CustomAIProvider:
    @staticmethod
    def getjsonparams(system_prompt: str, request: str) -> str:
        # Implement your AI API integration
        return process_with_custom_ai(system_prompt, request)

# Register and use your provider
processor = AIPostprocessor(work_dir)
processor.register_provider("custom", CustomAIProvider)
processor.run_postprocessing(markdown_file, "custom")

📊 Performance

Benchmarks

Document Type Pages Processing Time Memory Usage
Research Paper 20 45 seconds 2.1 GB
Technical Book 200 6 minutes 4.8 GB
Magazine 50 2 minutes 1.9 GB

Results on NVIDIA RTX 3080 with 16GB RAM

Optimization Tips

  • Use GPU acceleration for 3-5x speed improvement
  • Adjust batch multiplier based on available memory
  • Process in chunks for very large documents
  • Enable AI postprocessing for best quality (slower)

🆚 Comparison

Feature PDF2EPUB calibre pandoc
AI Enhancement ✅ ❌ ❌
Layout Detection ✅ ⚠️ ⚠️
GPU Acceleration ✅ ❌ ❌
Python API ✅ ⚠️ ⚠️
Plugin System ✅ ✅ ❌
CLI Interface ✅ ✅ ✅

🚢 Deployment

Docker

FROM python:3.11-slim

RUN pip install pdf2epub[full]

WORKDIR /workspace
ENTRYPOINT ["pdf2epub"]

GitHub Actions

- name: Convert PDFs
  run: |
    pip install pdf2epub[full]
    pdf2epub documents/*.pdf

Production Deployment

import pdf2epub
from pathlib import Path

def production_converter(pdf_path: str) -> dict:
    """Production-ready PDF conversion with error handling."""
    try:
        output_dir = pdf2epub.convert_pdf_to_markdown(
            pdf_path, 
            batch_multiplier=2,  # Conservative memory usage
            max_pages=1000      # Prevent runaway processing
        )
        
        epub_path = pdf2epub.convert_to_epub(output_dir)
        
        return {
            "status": "success",
            "markdown_path": output_dir,
            "epub_path": epub_path,
            "processing_time": time.time() - start_time
        }
        
    except Exception as e:
        return {
            "status": "error", 
            "error": str(e)
        }

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Contributing Steps

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Test your changes: pytest
  5. Format code: black .
  6. Submit a pull request

See CONTRIBUTING.md for detailed guidelines.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

This project builds upon excellent open-source libraries:

📈 Project Status

  • Version: 0.1.0 (Beta)
  • Status: Active development
  • Python: 3.9+ supported
  • Testing: 49% coverage, 100% pass rate
  • CI/CD: GitHub Actions
  • Documentation: Comprehensive

🔗 Links

📞 Support


Transform your PDFs into beautiful, accessible EPUBs with AI-powered enhancement! 🚀📚

Metadata

Release files for pdf2epub 0.1.2

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

Source distribution (sdist)

Source distribution for pdf2epub 0.1.2
File Size Uploaded
pdf2epub-0.1.2.tar.gz 58.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdf2epub 0.1.2
File Interpreter ABI Platform
pdf2epub-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 98.3 kB

Release files / pdf2epub-0.1.2.tar.gz

Download URL pdf2epub-0.1.2.tar.gz
Size 58.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b4e217b2ad835b08dd52743bd934805498eaf20b98e0fdeb32f6496c538735bc
BLAKE2b-256 checksum
How to use checksums
e83e5ec74097a007e070bf3c69f0a18b6238e086762c2df18f9e00fda4f1d205
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2025.

Transparency log

Release files / pdf2epub-0.1.2-py3-none-any.whl

Download URL pdf2epub-0.1.2-py3-none-any.whl
Size 40.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d45ab608d827d2b0e62ff4f5deba94ec0117dba916419e5e664863fd99755c3b
BLAKE2b-256 checksum
How to use checksums
6ffde31391f2b9f015443f3db1122b307b9b523c52aae0f2dcf9a250fe7ecf9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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