Skip to main content

pdf2md: PDF to Markdown Converter

pdf2md is an open-source Python library and CLI tool for converting PDF documents into clean, page-wise Markdown files. It leverages modern, GPU-accelerated OCR and layout detection models from the Hugging Face ecosystem, with robust fallbacks to widely used tools like EasyOCR and Tesseract.

[Image of a PDF document on the left being converted to a Markdown document on the right with images and text blocks]

Features

  • Multi-Backend OCR: Supports TrOCR (Hugging Face), EasyOCR, and Tesseract.
  • Layout-Aware: Uses layoutparser (optional) to intelligently detect text, image, and table blocks, with a heuristic fallback.
  • Resource-Aware: Explicitly manages GPU memory and resources to prevent leaks.
  • CLI & Library: Use it as a powerful command-line tool or integrate it into your Python projects.
  • Docker Support: CPU-only Docker image is provided by default, with clear instructions for GPU acceleration.

Quickstart (CLI)

  1. Create a virtual environment:
    python -m venv venv
    source venv/bin/activate
    
  2. Install the library and dependencies:
    pip install ".[all]" # Installs all optional dependencies for full functionality
    
  3. Run a conversion:
    # Convert a scanned document using pytesseract (CPU-only)
    pdf2md --input documents/scanned_book.pdf --out output/ --backend pytesseract --layout heuristic
    

Docker Usage

A Dockerfile is provided for running pdf2md in a containerized environment. By default, it's configured for CPU-only mode.

  1. Build the CPU image:
    docker build -t pdf2md .
    
  2. Run the CLI (CPU-only):
    docker run --rm -v $(pwd):/data pdf2md --input /data/sample.pdf --out /data/output --backend easyocr
    

How to Enable GPU Support

To run pdf2md with GPU acceleration, you need to use a base image with CUDA and install the correct PyTorch wheel.

  1. Modify Dockerfile: Uncomment the FROM nvidia/cuda:11.8.0-base-ubuntu22.04 and WORKDIR /app lines, and comment out the CPU base image.
  2. Update PyTorch Installation: Change the PyTorch install command to point to a CUDA-enabled wheel, for example: pip install torch==2.1.0+cu118 --index-url https://download.pytorch.org/whl/cu118. Note: Check the official PyTorch website for the latest compatible wheel URL.
  3. Use docker-compose: The docker-compose.yml is pre-configured to enable NVIDIA container runtime support. Uncomment the runtime: nvidia line under the pdf2md service.
  4. Build and run (GPU):
    # Build with new Dockerfile
    docker build -t pdf2md:gpu .
    # Run with docker-compose
    docker-compose up
    

Contributing & Testing

Running Tests

To run the unit and integration tests, first install the test dependencies:

pip install ".[test]"
pytest

Metadata

Release files for pdf2md-converter 0.1.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 pdf2md-converter 0.1.0
File Size Uploaded Provenance Actions
pdf2md_converter-0.1.0.tar.gz 10.0 kB Without provenance Details for pdf2md_converter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdf2md-converter 0.1.0
File Interpreter ABI Platform Actions
pdf2md_converter-0.1.0-py3-none-any.whl Python 3 none any Details for pdf2md_converter-0.1.0-py3-none-any.whl

Total release size: 20.5 kB

Release files / pdf2md_converter-0.1.0.tar.gz

Download URL pdf2md_converter-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c53b731da9eba74334489a89176e325497af791db69716bcbe678148f44eb975
BLAKE2b-256 checksum
How to use checksums
cab4715e3bb5dca1aee00e8b41e207aa47409638454f871695a2eadfc3cc173a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Release files / pdf2md_converter-0.1.0-py3-none-any.whl

Download URL pdf2md_converter-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1849bcb0dacbc2986e4edbde889a979aecca300bd92440f3ea983ed6ebd5e589
BLAKE2b-256 checksum
How to use checksums
7e2500b86437af38c18198bdb9148e18bb8a97a3314ae8d4f7a8be77952f5cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Security for pdf2md-converter 0.1.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

0.1.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