This script automates the process of converting images in a folder into a PDF, placing each image on a new page of an A4 document. It also ensures that there is space at the top of each page for additional content (e.g., text). The script adjusts the image sizes to fit within the page boundaries while preserving their aspect ratio.
- Convert all images (PNG files) in a specified folder to a PDF.
- Automatically resize images to fit within A4 page boundaries.
- Leave a configurable margin at the top of each page for content.
- Each image is placed at the bottom of the page to ensure space for content at the top.
To run the script, you need to install the required Python libraries. You can easily install them using the requirements.txt
file provided.
-
Clone or download the repository.
-
Navigate to the project directory.
-
Install the required dependencies by running:
pip install -r requirements.txt
-
Place all the images (PNG files) that you want to include in the PDF in a folder.
-
Modify the
image_folder
variable in the script to point to the folder containing your images, and adjust theoutput_pdf
to specify the name of the resulting PDF file.
NOTE : DONT FORGET TO CHANGE THE CONTENTS OF VARIABLES
image_folder = "path/to/your/folder" # Folder containing your PNG images
output_pdf = "output.pdf" # Output PDF file name
- Run the script:
python makepdf.py
This will generate a PDF with all the images from the specified folder.