Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RajeebLochan/pdf-to-img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

PDF to Image (PyMuPDF)

Small CLI to convert PDF pages to images using PyMuPDF. No Poppler required on Windows.

Features

  • 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

Requirements

  • 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 pymupdf

Usage (CLI)

Show help:

py main.py -h

Quick 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 jpg

Higher DPI:

py main.py "path\to\input.pdf" --dpi 300

Specific pages (1–3 and 7):

py main.py "path\to\input.pdf" --pages 1-3,7

Grayscale:

py main.py "path\to\input.pdf" --grayscale

Transparent background (PNG only):

py main.py "path\to\input.pdf" --transparent

Encrypted 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>_images next to the PDF (e.g., CE (1)_images)
  • Filenames like <pdf_stem>_p0001.png

Common use cases

  • 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

Programmatic usage (optional)

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,
)

Notes

  • 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.

About

PDF to image converter using python CLI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages