This Python script converts multiple images from a specified directory into a single PDF file. It supports various image formats and allows customization of sorting and output settings.
- Converts multiple images to a single PDF file.
- Supports image formats: JPG, JPEG, PNG, BMP, WebP, TIFF.
- Sorts images by filename (natural sort) or modification time.
- Customizable output filename, image extensions, and sorting method.
- High-quality PDF output with configurable DPI and image quality.
- Python 3.x
Pillowlibrary (for image processing)
-
Clone the repository:
git clone https://github.com/yourusername/image-to-pdf-converter.git cd image-to-pdf-converter -
Install the required dependencies:
pip install pillow
Run the script from the command line with the following arguments:
python main.py <input_dir> [options]input_dir: Path to the directory containing the images.-o,--output: Output PDF filename (default:output.pdf).-e,--ext: Image extensions to include, separated by commas (default:jpg).--sort-by: Sorting method for images (nameormtime, default:name).
-
Convert all
.jpgimages in theimagesdirectory to a PDF:python main.py images
-
Convert
.pngand.jpgimages, sort by modification time, and save asmy_output.pdf:python main.py images -o my_output.pdf -e png,jpg --sort-by mtime
The script generates a PDF file in the specified output location. A success message is displayed with the number of pages and the absolute path of the PDF file.
- The script validates the input directory and checks for supported image files.
- If an error occurs (e.g., invalid directory or no images found), an error message is displayed, and the script exits.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to contribute, report issues, or suggest improvements!