Coders Packet

Python Script to Convert image files to PDF

By Paras Rawat

A python script to convert image files to pdf using the Image module of the PIL library

First, you would need to install  Pillow using the 'pip install pillow' command on your cmd.

Now import os and Image module from PIL.

We will access the image files that we need to convert to pdf using the listdir method of the os library.

Now create an image object and then covert the image to 'RGB' mode because Pillow can't save a four-channel image('RGBA') file to pdf. If the image file has four-channels, we'll need to strip the last one before saving the image file to pdf.

Now save the image file to pdf.

Download Complete Code


No comments yet