Skip to main content

Convert PDF files to Markdown using Google Gemini API

Project description

pdf2md

PyPI version Python License: MIT

Converts PDF files to Markdown using the Gemini API.

Installation

From PyPI (Recommended)

pip install pdf2md

For pre-release versions:

pip install --pre pdf2md

From Source

git clone https://github.com/marcbadiam/pdf2md.git
cd pdf2md
pip install -e .

Project Files

  • pdf2md.py: Main conversion script.
  • setup.sh: Setup helper for API key configuration and command installation.

Dependencies

System dependencies:

  • Python 3.8 or later.
  • Bash.
  • Coreutils (install command).
  • Internet access to call the Gemini API.

Installation

  1. Enter the project directory.
  2. Run the setup script:
bash setup.sh

The setup.sh script:

  • Prompts for the API key in the terminal.
  • Stores MY_GEMINI_API_KEY in the active shell rc file.
  • Installs the pdf2md command in /usr/local/bin if writable.
  • Falls back to ~/.local/bin when /usr/local/bin is not writable.

If installation uses ~/.local/bin and it is not in PATH, add this line to your rc file:

export PATH="$HOME/.local/bin:$PATH"

Usage

Direct script usage:

python3 pdf2md.py <input.pdf> [output.md]

Installed command usage:

pdf2md <input.pdf> [output.md]

Behavior:

  • input.pdf: Input PDF file path.
  • output.md: Optional output file path. If omitted, the script uses the input filename with .md.

Examples

python3 pdf2md.py document.pdf
python3 pdf2md.py document.pdf output.md
pdf2md document.pdf
pdf2md document.pdf output.md

Configuration

Set your Gemini API key as an environment variable:

export MY_GEMINI_API_KEY="your_api_key_here"

For permanent configuration, add it to your shell rc file (~/.bashrc, ~/.zshrc, etc.):

echo 'export MY_GEMINI_API_KEY="your_api_key_here"' >> ~/.bashrc
source ~/.bashrc

Notes

  • MY_GEMINI_API_KEY must be set for API requests to work.
  • Open a new terminal or reload your shell session after rc file changes.

Features

  • 📄 PDF to Markdown conversion using Google Gemini API
  • 🔍 Advanced OCR with support for complex layouts
  • 📊 Table detection and formatting
  • 🔢 Mathematical formulas rendered in LaTeX
  • 💻 Code block detection with syntax highlighting
  • 🖼️ Image handling with transcription and descriptions
  • 🌍 Multi-language support preserves original document language

Requirements

  • Python 3.8 or higher
  • Google Gemini API key
  • Internet connection

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

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

pdf_to_md-0.1.0b1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

pdf_to_md-0.1.0b1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pdf_to_md-0.1.0b1.tar.gz.

File metadata

  • Download URL: pdf_to_md-0.1.0b1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pdf_to_md-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 2ca6849019c05c79aaa8ecbaa2d25029ce60af71643959e3629dea4216afaa54
MD5 32b8b4408650346d330e86ccb9fabe2c
BLAKE2b-256 607edbcae1296ad8f9c8caf6d1b5a3e75e6ed269913890fdf94af975197f218e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_to_md-0.1.0b1.tar.gz:

Publisher: pypi-publish.yml on marcbadiam/pdf2md

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

File details

Details for the file pdf_to_md-0.1.0b1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pdf_to_md-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 10f909350e4d339a04507190591c2cc6d21dec920ad472c5f96837398315d886
MD5 9e2fbef22de9bceb73cc777006548852
BLAKE2b-256 36b758fb9c4cb8730a447eb714ab4b8317790f3806a5cff20041d128d9b66d0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdf_to_md-0.1.0b1-py3-none-any.whl:

Publisher: pypi-publish.yml on marcbadiam/pdf2md

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