Convert PDF files to Markdown using Google Gemini API
Project description
pdf2md
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 (
installcommand). - Internet access to call the Gemini API.
Installation
- Enter the project directory.
- Run the setup script:
bash setup.sh
The setup.sh script:
- Prompts for the API key in the terminal.
- Stores
MY_GEMINI_API_KEYin the active shell rc file. - Installs the
pdf2mdcommand in/usr/local/binif writable. - Falls back to
~/.local/binwhen/usr/local/binis 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_KEYmust 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca6849019c05c79aaa8ecbaa2d25029ce60af71643959e3629dea4216afaa54
|
|
| MD5 |
32b8b4408650346d330e86ccb9fabe2c
|
|
| BLAKE2b-256 |
607edbcae1296ad8f9c8caf6d1b5a3e75e6ed269913890fdf94af975197f218e
|
Provenance
The following attestation bundles were made for pdf_to_md-0.1.0b1.tar.gz:
Publisher:
pypi-publish.yml on marcbadiam/pdf2md
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pdf_to_md-0.1.0b1.tar.gz -
Subject digest:
2ca6849019c05c79aaa8ecbaa2d25029ce60af71643959e3629dea4216afaa54 - Sigstore transparency entry: 1066452393
- Sigstore integration time:
-
Permalink:
marcbadiam/pdf2md@51bf9c4ce558c79d6312be572859005384cd2636 -
Branch / Tag:
refs/tags/v0.1.0b2 - Owner: https://github.com/marcbadiam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@51bf9c4ce558c79d6312be572859005384cd2636 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f909350e4d339a04507190591c2cc6d21dec920ad472c5f96837398315d886
|
|
| MD5 |
9e2fbef22de9bceb73cc777006548852
|
|
| BLAKE2b-256 |
36b758fb9c4cb8730a447eb714ab4b8317790f3806a5cff20041d128d9b66d0b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pdf_to_md-0.1.0b1-py3-none-any.whl -
Subject digest:
10f909350e4d339a04507190591c2cc6d21dec920ad472c5f96837398315d886 - Sigstore transparency entry: 1066452414
- Sigstore integration time:
-
Permalink:
marcbadiam/pdf2md@51bf9c4ce558c79d6312be572859005384cd2636 -
Branch / Tag:
refs/tags/v0.1.0b2 - Owner: https://github.com/marcbadiam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@51bf9c4ce558c79d6312be572859005384cd2636 -
Trigger Event:
push
-
Statement type: