A simple Python CLI utility that converts all images in a folder to a single PDF file.
- Converts multiple image formats to a single PDF
- Preserves image quality (lossless conversion)
- One image per page with aspect ratio preserved
- Alphabetical ordering by filename
- Simple command-line interface
- JPEG (
.jpg,.jpeg) - PNG (
.png) - TIFF (
.tiff,.tif) - WebP (
.webp) - BMP (
.bmp)
This project uses uv for dependency management.
# Install dependencies
uv syncYou can create a config.yaml file to set base directories:
# Base source directory - folder argument is relative to this pathsource_dir: C:/Users/JohnDoe/Documents/Scans/# Target directory where PDFs are savedtarget_dir: C:/Users/JohnDoe/Documents/PDF/With this configuration, uv run pdfer "Beethoven Moonlight Sonata" will:
- Read images from:
C:/Users/JohnDoe/Documents/Scans/Beethoven Moonlight Sonata - Save PDF to:
C:/Users/JohnDoe/Documents/PDF/Beethoven Moonlight Sonata.pdf
Basic usage:
uv run pdfer [folder] [output.pdf]Both arguments are optional:
folder: Folder name (relative tosource_dirin config.yaml) or absolute path. If omitted, usessource_diritself.output.pdf: Output filename. If omitted, defaults to<folder_name>.pdfintarget_dirfrom config.yaml.
Convert all images in the photos folder to album.pdf:
uv run pdfer photos album.pdfConvert images in photos to photos.pdf (using target_dir from config):
uv run pdfer photosConvert images from current directory using defaults:
uv run pdferuv run pdfer --help- Loads configuration from
config.yamlif present (optional) - Resolves the source folder (relative to
source_dirif configured) - Scans the folder for supported image files (non-recursive, top-level only)
- Sorts images alphabetically by filename
- Converts them to a single PDF file using lossless compression
- Saves the PDF to
target_dirwith automatic naming if output not specified - Each image appears on its own page with preserved aspect ratio
- Non-recursive: Only scans the top-level folder, not subdirectories
- Alphabetical ordering: Images are sorted by filename. Rename files if you need a specific order (e.g.,
001-first.jpg,002-second.jpg) - Lossless conversion: Uses
img2pdfwhich embeds images without recompression, preserving quality - Error handling: Provides clear error messages for common issues
Make sure your folder contains files with supported extensions. The tool only searches the top-level folder, not subdirectories.
Ensure you have:
- Read permissions for the source folder
- Write permissions for the output directory
If an image file is corrupted or not a valid image format, the conversion will fail with an error message.
- img2pdf: Used for lossless image-to-PDF conversion
- Pillow: Image processing library (dependency of img2pdf)
- PyYAML: Configuration file parsing
- pathlib: Modern Python file path handling
- argparse: Command-line argument parsing
MIT