In our example, I’ll be storing the PDF file under the same path where the original image is stored (from Step 2): Step 3: Convert the image to PDF using Pythonįor the final step, you can use the template below in order to convert the image to PDF: from PIL import Image
In my case, the image is stored under the following path:
Next, capture the path where your image is stored. Step 2: Capture the path where your image is stored If you’re a Windows user, you may follow this guide for the instructions to install a package using pip. To start, install the PIL package using the command below: pip install Pillow Steps to Convert Images to PDF using Python Step 1: Install the PIL package Later, you’ll also see how to convert a list of images to PDF.
Im1.save(r'path where the pdf will be stored\new file name.pdf') Image1 = Image.open(r'path where the image is stored\file name.png') To begin, here is a template that you can use to convert a png image to PDF using Python (for JPEG, use the file extension of ‘jpg’): from PIL import Image The PIL package will be used to accomplish this goal. In this short guide, you’ll see how to convert images to PDF using Python.