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.
- Overview
- Features
- Prerequisites
- Installation
- Usage
- Code Structure
- Implementation Details
- Enhancement Ideas
- Contributing
- License
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).
- 📄 Convert all pages in a PDF to image(s)
- ⚙️ Configure DPI (e.g., 150–300) for resolution control
- 🗂️ Supports output formats
.jpgand.png - 🔁 Batch process multiple PDFs in a folder
- 🧰 Easy CLI and importable library interface
- Python 3.7+
- System dependency: Poppler tools (e.g.,
pdftoppm) installed and available inPATH - Python libraries:
pip install pdf2imageOr for enhanced rendering using PyMuPDF:
pip install PyMuPDFgit clone https://github.com/MisaghMomeniB/PDF2Picture-Python.git
cd PDF2Picture-Python
pip install -r requirements.txt # includes pdf2imageEnsure pdftoppm is set up on your system.
Convert a PDF to PNG images at 200 DPI:
python pdf2picture.py \
--input doc.pdf \
--output-dir pages/ \
--dpi 200 \
--format pngThis produces:
pages/doc_page_1.pngpages/doc_page_2.png- …
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")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
argparseand calls conversion logic
- 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
- ✅ 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
Contributions are welcome!
- Fork the repository
- Create a
feature/...branch - Add clean, documented code
- Open a Pull Request
Released under the MIT License — see LICENSE for details.