https://github.com/misaghmomenib/pdf2picture-python
A Lightweight Python Tool to Seamlessly Convert Pdf Documents Into High-quality Images. Ideal for Developers Needing Fast and Efficient Pdf-to-image Transformation for Various Use Cases Such as Previews, Archiving, or Content Extraction.
https://github.com/misaghmomenib/pdf2picture-python
converter git open-source pdf-converter picture-converter python
Last synced: 2 months ago
JSON representation
A Lightweight Python Tool to Seamlessly Convert Pdf Documents Into High-quality Images. Ideal for Developers Needing Fast and Efficient Pdf-to-image Transformation for Various Use Cases Such as Previews, Archiving, or Content Extraction.
- Host: GitHub
- URL: https://github.com/misaghmomenib/pdf2picture-python
- Owner: MisaghMomeniB
- License: gpl-3.0
- Created: 2024-10-27T10:52:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-10T15:10:19.000Z (over 1 year ago)
- Last Synced: 2025-06-07T22:41:01.220Z (about 1 year ago)
- Topics: converter, git, open-source, pdf-converter, picture-converter, python
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# πΌοΈ PDF2Picture (Python)
A lightweight Python tool to **convert PDF documents into images** (perβpage JPG or PNG). Ideal for document previews, thumbnail generation, or embedding pages as images in web and mobile apps.
---
## π Table of Contents
1. [Overview](#overview)
2. [Features](#features)
3. [Prerequisites](#prerequisites)
4. [Installation](#installation)
5. [Usage](#usage)
6. [Code Structure](#code-structure)
7. [Implementation Details](#implementation-details)
8. [Enhancement Ideas](#enhancement-ideas)
9. [Contributing](#contributing)
10. [License](#license)
---
## π‘ Overview
PDF2Picture converts each page of a PDF into high-quality image files. It uses libraries like **pdf2image** or **PyMuPDF** to render pages and supports batch conversions, DPI control, and format options (JPG/PNG).
---
## β
Features
- π Convert all pages in a PDF to image(s)
- βοΈ Configure DPI (e.g., 150β300) for resolution control
- ποΈ Supports output formats `.jpg` and `.png`
- π Batch process multiple PDFs in a folder
- π§° Easy CLI and importable library interface
---
## π οΈ Prerequisites
- Python **3.7+**
- System dependency: **Poppler** tools (e.g., `pdftoppm`) installed and available in `PATH`
- Python libraries:
```bash
pip install pdf2image
````
Or for enhanced rendering using PyMuPDF:
```bash
pip install PyMuPDF
```
---
## βοΈ Installation
```bash
git clone https://github.com/MisaghMomeniB/PDF2Picture-Python.git
cd PDF2Picture-Python
pip install -r requirements.txt # includes pdf2image
```
Ensure `pdftoppm` is set up on your system.
---
## π Usage
### CLI Example
Convert a PDF to PNG images at 200 DPI:
```bash
python pdf2picture.py \
--input doc.pdf \
--output-dir pages/ \
--dpi 200 \
--format png
```
This produces:
* `pages/doc_page_1.png`
* `pages/doc_page_2.png`
* β¦
### Python Module
```python
from pdf2picture import convert_pdf_to_images
images = convert_pdf_to_images(
pdf_path="doc.pdf",
output_dir="out/",
dpi=150,
fmt="jpg"
)
print(f"Converted {len(images)} pages")
```
---
## π Code Structure
```
PDF2Picture-Python/
βββ pdf2picture.py # CLI interface & wrapper logic
βββ pdf2picture_lib.py # Core conversion functions
βββ requirements.txt
βββ README.md # This file
```
* `convert_pdf_to_images(...)`: handles conversion and returns file paths
* CLI parses options via `argparse` and calls conversion logic
---
## π Implementation Details
* Uses `pdf2image.convert_from_path(...)` with DPI and format options
* Creates output directory if missing and saves images with page index
* Handles errors for invalid PDFs and missing Poppler tools
---
## π‘ Enhancement Ideas
* β
Add **PDF page range** selection (e.g., pages 1β5)
* ποΈ Support **image compression** or resizing
* βοΈ Integrate with **web frameworks** (Flask/FastAPI) for upload/download
* π¦ Export images to **PDF or thumbnails** in a ZIP
* π§ͺ Add **unit tests** and error-handling improvements
---
## π€ Contributing
Contributions are welcome!
1. Fork the repository
2. Create a `feature/...` branch
3. Add clean, documented code
4. Open a Pull Request
---
## π License
Released under the **MIT License** β see `LICENSE` for details.