An open API service indexing awesome lists of open source software.

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.

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.