How to convert images to PDF file using Python

Free Python Code - Aug 30 '23 - - Dev Community

Hi 🙂🖐

In this post, I will share with you how to convert images to PDF files using Python.

step 1

You need to install Pillow liblary from here pip install Pillow

step 2

You need to some images to convert them to PDF file

step 3

Load all images and convert them.

from PIL import Image
from os import listdir

def images_to_pdf():
    images = [Image.open(f'images/{i}') for i in listdir('images')]
    images[0].save('out.pdf', save_all=True, append_images = images)

images_to_pdf()

Enter fullscreen mode Exit fullscreen mode

Now we're done 🤗

Don't forget to like and follow 🙂

Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .