› Forums › Python › How to Combine Multiple Images into One PDF Using Python (Step-by-Step Tutorial)
- This topic is empty.
-
AuthorPosts
-
February 8, 2026 at 4:25 pm #6031
In many programming projects—especially in courses like MIT’s introductory CS programs—you are often required to submit multiple images as a single PDF file. Instead of using online tools, you can do this professionally using Python and the Pillow library.
In this tutorial, you will learn how to:
✅ Open multiple images in Python
✅ Convert them to PDF-compatible format
✅ Combine them into a multi-page PDF
✅ Understand howappend_imagesworksNo prior experience with PDF generation is required.
🧩 Step 1: Install Pillow (If Not Already Installed)
Pillow is the modern image-processing library for Python.
Install it using:
pip install pillow
🧩 Step 2: Import the Image Module
Start by importing
Imagefrom Pillow:from PIL import ImageThis module allows you to open, edit, and save images.
🧩 Step 3: Open and Convert Images to RGB
PDF files require images to be in RGB mode.
So we first open each image and convert it.images = [ Image.open("image1.png").convert("RGB"), Image.open("image2.bmp").convert("RGB"), Image.open("image3.jpg").convert("RGB") ]Why
.convert("RGB")?Some images may be:
- grayscale (
"L") - palette-based (
"P")
These formats may cause errors when saving as PDF.
Converting to"RGB"ensures compatibility.
🧩 Step 4: Save Images as a Multi-Page PDF
Now we use Pillow’s
.save()method:images[0].save( "output.pdf", save_all=True, append_images=images[1:] )
🧠 Understanding This Code
Let’s break it down:
images[0].save(...)Uses the first image as the first page of the PDF.
"output.pdf"Name of the PDF file to be created.
save_all=TrueTells Pillow that multiple pages will be saved.
append_images=images[1:]Adds the remaining images as extra pages.
images[1:]means “all images except the first one.”
🧩 Step 5: Run the Script
Save your file as
make_pdf.pyand run:python make_pdf.pyYou will get:
output.pdfcontaining all your images in order.
✅ Example: MIT Assignment Submission
If your files are:
filtered_image_15_kerb.png hidden1_unhidden_kerb.bmp hidden2_unhidden_kerb.bmpUse:
from PIL import Image images = [ Image.open("filtered_image_15_kerb.png").convert("RGB"), Image.open("hidden1_unhidden_kerb.bmp").convert("RGB"), Image.open("hidden2_unhidden_kerb.bmp").convert("RGB") ] images[0].save( "submission.pdf", save_all=True, append_images=images[1:] )
🛠 Optional: Resize Images Before Combining
If images are too large, resize them first:
images = [img.resize((800, 1000)) for img in images]Do this before saving.
⚠️ Common Errors and Fixes
❌ Error: “cannot save mode L as PDF”
✅ Fix: Add
.convert("RGB")
❌ Only one page in PDF
✅ Fix: Add
save_all=Trueandappend_images
❌ FileNotFoundError
✅ Fix: Check file names and folder location
🌍 Real-World Uses
This technique is useful in:
- college assignments
- project documentation
- scanning workflows
- reports and portfolios
- automation systems
Many companies automate report generation using this method.
📌 Final Takeaway
Using Python and Pillow, you can easily convert multiple images into a professional, multi-page PDF using just a few lines of code—no online tools required.
- grayscale (
-
AuthorPosts
- You must be logged in to reply to this topic.

