DEV Community

Free Python Code
Free Python Code

Posted on

How to convert images to PDF file using Python

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

Top comments (5)

Collapse
 
thitkhotauhp9x profile image
thitkhotauhp9x

I want convert pdf to image. Have any way to do that? (I try with pdf2image, wand. It's success. But they seem have problem with license.

Collapse
 
freepythoncode profile image
Free Python Code
Collapse
 
thitkhotauhp9x profile image
thitkhotauhp9x

Hic, I cannot access your link.

Thread Thread
 
freepythoncode profile image
Free Python Code
Thread Thread
 
freepythoncode profile image
Free Python Code