Small CLI to convert PDF pages to images using PyMuPDF. No Poppler required on Windows.
- Convert all or selected pages
- Control output DPI (quality/size)
- Formats: PNG, JPG/JPEG, TIFF
- Optional transparent background (PNG only)
- Optional grayscale
- Supports password-protected PDFs
- Python 3.8+
- Dependencies: PyMuPDF (install via pip or requirements.txt)
Install on Windows (PowerShell):
py -m venv .venv
.\.venv\Scripts\Activate.ps1
# Option A: install from requirements file (if present)
py -m pip install -r requirements.txt
# Option B: install directly
py -m pip install pymupdfShow help:
py main.py -hQuick start (your files in this folder):
# From c:\Users\Administrator\Desktop\pdf-to-img
py .\main.py ".\CE (1).pdf"
py .\main.py ".\SGS (1).PDF"
py .\main.py ".\TUV报告2019新(1) (1).pdf"Basic (all pages to PNG at 200 DPI):
py main.py "path\to\input.pdf"Choose output folder:
py main.py "path\to\input.pdf" -o ".\out"JPEG format:
py main.py "path\to\input.pdf" -f jpgHigher DPI:
py main.py "path\to\input.pdf" --dpi 300Specific pages (1–3 and 7):
py main.py "path\to\input.pdf" --pages 1-3,7Grayscale:
py main.py "path\to\input.pdf" --grayscaleTransparent background (PNG only):
py main.py "path\to\input.pdf" --transparentEncrypted PDF:
py main.py "path\to\input.pdf" --password "your_password"Convert all PDFs in the current folder:
Get-ChildItem -Filter *.pdf -File | ForEach-Object { py .\main.py $_.FullName -o .\out }Output:
- Defaults to a folder named
<pdf_stem>_imagesnext to the PDF (e.g.,CE (1)_images) - Filenames like
<pdf_stem>_p0001.png
- Generate thumbnails for PDFs
- Export slides or pages as images for web
- Preprocess pages (grayscale, fixed DPI) for OCR pipelines
- Share pages as lightweight JPEGs
- Extract only a subset of pages for documentation
You can also call the function from Python:
from pathlib import Path
from main import convert_pdf_to_images
convert_pdf_to_images(
pdf_path=Path(r"path\to\file.pdf"),
out_dir=Path(r".\out"),
image_format="png",
dpi=200,
pages="1-5",
transparent=False,
grayscale=False,
password=None,
)- Transparent background works only with PNG.
- Very high DPI can produce large images and use more memory.
- TIFF output is single-page per image (no multi-page TIFF).
- If you see “No module named fitz”, run:
py -m pip install pymupdf.