Python Tutorial To Convert Images to PDF Document Using Pillow Library

Python Tutorial To Convert Images to PDF Document Using Pillow Library

Welcome folks today in this tutorial i will be showing a tutorial on how to convert all images to a single pdf document using the pillow library. Let’s get started below there is a step by step guide a youtube video by myself follow the video and make this application from scratch

 

Requirements

 

pip install pillow

 

Pillow is a python library for image processing operations. This is a open source library and just go to your python project open cmd and execute top command to install the library

 

Converting single image to pdf document

 

from PIL import Image

image1 = Image.open('screenshot.png')
 
im1 = image1.convert('RGB')


imagelist = [im1]

im1.save('output.pdf')

 

Converting Multiple Images to a Single PDF Document

 

from PIL import Image

image1 = Image.open(r'C:\Users\Ron\Desktop\Test\image1.png')
image2 = Image.open(r'C:\Users\Ron\Desktop\Test\image2.png')
image3 = Image.open(r'C:\Users\Ron\Desktop\Test\image3.png')
image4 = Image.open(r'C:\Users\Ron\Desktop\Test\image4.png')
 
im1 = image1.convert('RGB')
im2 = image2.convert('RGB')
im3 = image3.convert('RGB')
im4 = image4.convert('RGB')

imagelist = [im2,im3,im4]

im1.save(r'C:\Users\Ron\Desktop\Test\myImages.pdf',save_all=True, append_images=imagelist)

Leave a Reply