1515
1616## Overview
1717
18- MarkPDFDown is designed to simplify the process of converting PDF documents into clean, editable Markdown text. By utilizing advanced multimodal AI models, it can accurately extract text, preserve formatting, and handle complex document structures including tables, formulas, and diagrams.
18+ MarkPDFDown is designed to simplify the process of converting PDF documents into clean, editable Markdown text. By utilizing advanced multimodal AI models through LiteLLM , it can accurately extract text, preserve formatting, and handle complex document structures including tables, formulas, and diagrams.
1919
2020## Features
2121
2222- ** PDF to Markdown Conversion** : Transform any PDF document into well-formatted Markdown
2323- ** Image to Markdown Conversion** : Transform image into well-formatted Markdown
24- - ** Multimodal Understanding** : Leverages AI to comprehend document structure and content
24+ - ** Multi-Provider Support** : Supports OpenAI and OpenRouter through LiteLLM
25+ - ** Flexible CLI** : Both file-based and pipe-based usage modes
2526- ** Format Preservation** : Maintains headings, lists, tables, and other formatting elements
26- - ** Customizable Model** : Configure the model to suit your needs
27+ - ** Page Range Selection** : Convert specific page ranges from PDF documents
28+ - ** Modular Architecture** : Clean, maintainable codebase with separation of concerns
2729
2830## Demo
2931![ ] ( https://raw.githubusercontent.com/markpdfdown/markpdfdown/refs/heads/master/tests/demo_02.png )
@@ -43,6 +45,8 @@ cd markpdfdown
4345# Install dependencies and create virtual environment
4446uv sync
4547
48+ # Install the package in development mode
49+ uv pip install -e .
4650```
4751
4852### Using conda
@@ -58,29 +62,106 @@ cd markpdfdown
5862# Install dependencies
5963pip install -e .
6064```
65+
66+ ## Configuration
67+
68+ MarkPDFDown uses environment variables for configuration. Create a ` .env ` file in your project directory:
69+
70+ ``` bash
71+ # Copy the sample configuration
72+ cp .env.sample .env
73+ ```
74+
75+ Edit the ` .env ` file with your settings:
76+
77+ ``` bash
78+ # Model Configuration
79+ MODEL_NAME=gpt-4o
80+
81+ # API Keys (LiteLLM automatically detects these)
82+ OPENAI_API_KEY=your-openai-api-key
83+ # or for OpenRouter
84+ OPENROUTER_API_KEY=your-openrouter-api-key
85+
86+ # Optional Parameters
87+ TEMPERATURE=0.3
88+ MAX_TOKENS=8192
89+ RETRY_TIMES=3
90+ ```
91+
92+ ### Supported Models
93+
94+ #### OpenAI Models
95+ ``` bash
96+ MODEL_NAME=gpt-4o
97+ MODEL_NAME=gpt-4o-mini
98+ MODEL_NAME=gpt-4-vision-preview
99+ ```
100+
101+ #### OpenRouter Models
102+ ``` bash
103+ MODEL_NAME=openrouter/anthropic/claude-3.5-sonnet
104+ MODEL_NAME=openrouter/google/gemini-pro-vision
105+ MODEL_NAME=openrouter/meta-llama/llama-3.2-90b-vision
106+ ```
107+
61108## Usage
109+
110+ ### File Mode (Recommended)
111+
62112``` bash
63- # Set up your OpenAI API key
64- export OPENAI_API_KEY=" your-api-key"
65- # Optionally, set up your OpenAI API base
66- export OPENAI_API_BASE=" your-api-base"
67- # Optionally, set up your OpenAI API model
68- export OPENAI_DEFAULT_MODEL=" your-model"
69-
70- # pdf to markdown
71- python main.py < tests/input.pdf > output.md
72-
73- # image to markdown
74- python main.py < input_image.png > output.md
113+ # Basic conversion
114+ markpdfdown --input document.pdf --output output.md
115+
116+ # Convert specific page range
117+ markpdfdown --input document.pdf --output output.md --start 1 --end 10
118+
119+ # Convert image to markdown
120+ markpdfdown --input image.png --output output.md
121+
122+ # Using python module
123+ python -m markpdfdown --input document.pdf --output output.md
124+ ```
125+
126+ ### Pipe Mode (Docker-friendly)
127+
128+ ``` bash
129+ # PDF to markdown via pipe
130+ markpdfdown < document.pdf > output.md
131+
132+ # Using python module
133+ python -m markpdfdown < document.pdf > output.md
75134```
76- ## Advanced Usage
135+
136+ ### Advanced Usage
137+
77138``` bash
78- python main.py page_start page_end < tests/input.pdf > output.md
139+ # Convert pages 5-15 of a PDF
140+ markpdfdown --input large_document.pdf --output chapter.md --start 5 --end 15
141+
142+ # Process multiple files
143+ for file in * .pdf; do
144+ markpdfdown --input " $file " --output " ${file% .pdf} .md"
145+ done
79146```
80147
81148## Docker Usage
149+
82150``` bash
83- docker run -i -e OPENAI_API_KEY=your-api-key -e OPENAI_API_BASE=your-api-base -e OPENAI_DEFAULT_MODEL=your-model jorbenzhu/markpdfdown < input.pdf > output.md
151+ # Build the image (if needed)
152+ docker build -t markpdfdown .
153+
154+ # Run with environment variables
155+ docker run -i \
156+ -e MODEL_NAME=gpt-4o \
157+ -e OPENAI_API_KEY=your-api-key \
158+ markpdfdown < input.pdf > output.md
159+
160+ # Using OpenRouter
161+ docker run -i \
162+ -e MODEL_NAME=openrouter/anthropic/claude-3.5-sonnet \
163+ -e OPENROUTER_API_KEY=your-openrouter-key \
164+ markpdfdown < input.pdf > output.md
84165```
85166
86167## Development Setup
@@ -126,7 +207,24 @@ ruff check --fix
126207- Python 3.9+
127208- [ uv] ( https://astral.sh/uv/ ) (recommended for package management) or conda/pip
128209- Dependencies specified in ` pyproject.toml `
129- - Access to the specified multimodal AI model
210+ - Access to supported LLM providers (OpenAI or OpenRouter)
211+
212+ ## Architecture
213+
214+ The project follows a modular architecture:
215+
216+ ```
217+ src/markpdfdown/
218+ ├── __init__.py # Package initialization
219+ ├── __main__.py # Entry point for python -m
220+ ├── cli.py # Command line interface
221+ ├── main.py # Core conversion logic
222+ ├── config.py # Configuration management
223+ └── core/ # Core modules
224+ ├── llm_client.py # LiteLLM integration
225+ ├── file_worker.py # File processing
226+ └── utils.py # Utility functions
227+ ```
130228
131229## Contributing
132230Contributions are welcome! Please feel free to submit a Pull Request.
@@ -150,10 +248,26 @@ Contributions are welcome! Please feel free to submit a Pull Request.
150248
151249Please ensure your code follows the project's coding standards by running the linting and formatting tools before submitting.
152250
251+ ## Changelog
252+
253+ ### v0.2.0 (Latest)
254+ - ** Breaking Changes** : Complete architecture refactor
255+ - ** New** : LiteLLM integration for multi-provider support
256+ - ** New** : Unified CLI with ` --input ` /` --output ` parameters
257+ - ** New** : Support for ` python -m markpdfdown ` execution
258+ - ** New** : Environment-based configuration with ` .env ` support
259+ - ** New** : OpenRouter support alongside OpenAI
260+ - ** Improved** : Modular codebase with better separation of concerns
261+ - ** Improved** : Enhanced error handling and logging
262+
263+ ### v0.1.0
264+ - Initial release with basic PDF to Markdown conversion
265+
153266## License
154267This project is licensed under the Apache License 2.0. See the LICENSE file for details.
155268
156269## Acknowledgments
270+ - Thanks to the developers of LiteLLM for providing unified LLM access
157271- Thanks to the developers of the multimodal AI models that power this tool
158272- Inspired by the need for better PDF to Markdown conversion tools
159273
@@ -164,4 +278,4 @@ This project is licensed under the Apache License 2.0. See the LICENSE file for
164278[ Size ] : https://img.shields.io/docker/image-size/jorbenzhu/markpdfdown/latest?color=066da5&label=size
165279[ Pulls ] : https://img.shields.io/docker/pulls/jorbenzhu/markpdfdown.svg?style=flat&label=pulls&logo=docker
166280[ Tag ] : https://img.shields.io/github/release/markpdfdown/markpdfdown.svg
167- [ License ] : https://img.shields.io/github/license/markpdfdown/markpdfdown
281+ [ License ] : https://img.shields.io/github/license/markpdfdown/markpdfdown
0 commit comments