Home
About
Resume
Projects
Links
Blog
Back to Contents
# Python Convert PNG to PDF using PIL #### Installation ```bash pip install Pillow ``` #### Usage Please refer to [Pillow’s documentation](https://pillow.readthedocs.io/en/stable/) #### Working Example ##### Aim: - To convert PNG(s) to a single PDF ##### Code: ```python from PIL import Image #### Define Functions ##### class png2pdfConverter(): def __init__(self,images_path_list): self.images_path_list = images_path_list def exportPDF(self,output_path): image_list = [] for image_path in self.images_path_list: temp_image = Image.open(image_path).convert('RGB') image_list.append(temp_image) image_list[0].save(output_path,save_all=True, append_images=image_list[1:]) ########################## image_paths = ["./a.png","./b.png","someDir/c.png"] output_path = "./output.pdf" p2pc = png2pdfConverter(image_paths) p2pc.exportPDF(output_path) ``` #### Source **Documentation link**: [Pillow’s documentation](https://pillow.readthedocs.io/en/stable/)
Previous Post:
Python Manipulate PDF
Next Post:
Python Capture Webpage
Loading