How to convert images in pdf with PIL and python

Here’s how to convert all images in a folder into a pdf file with just python and PIL!

First install PIL

pip install pillow

then save this script into the folder with the images and launch it

from PIL import Image
from glob import glob

iml = []
im1 = Image.open(glob("*.png")[0])
for img in glob("*.png"):
    iml.append(Image.open(img))
pdf = "turismo1.pdf"

im1.save(pdf, "PDF" ,resolution=100.0, save_all=True, append_images=iml)

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.