img2pdf is an open source Python package to convert images to pdf format. It includes another module Pillow which can also be used to enhance image (Brightness, contrast and other things)
Use this command to install the packages
pip install img2pdf
Below is the implementation:
Image can be converted into pdf bytes using img2pdf.convert() functions provided by img2pdf module, then the pdf file opened in wb mode and is written with the bytes.
# Python3 program to convert image to pfd # using img2pdf library # importing necessary libraries import img2pdf from PIL import Image import os # storing image path img_path = "C:/Users/Admin/Desktop/GfG_images/do_nawab.png" # storing pdf path pdf_path = "C:/Users/Admin/Desktop/GfG_images/file.pdf" # opening image image = Image.open(img_path) # converting into chunks using img2pdf pdf_bytes = img2pdf.convert(image.filename) # opening or creating pdf file file = open(pdf_path, "wb") # writing pdf files with chunks file.write(pdf_bytes) # closing image file image.close() # closing pdf file file.close() # output print("Successfully made pdf file") |
Output:
Successfully made pdf file
Recommended Posts:
- Send PDF File through Email using pdf-mail module
- Python - Convert simple lines to bulleted lines using the Pyperclip module
- Getting started with Scikit-image: image processing in Python
- Python | Writing to an excel file using openpyxl module
- Python | Reading an excel file using openpyxl module
- Testing in Python using doctest module
- Python | ASCII art using pyfiglet module
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Plotting charts in excel sheet using openpyxl module | Set - 1
- Python | Plotting charts in excel sheet using openpyxl module | Set – 2
- Python | Plotting charts in excel sheet using openpyxl module | Set 3
- Python | Create and write on excel file using xlsxwriter module
- Python | Plotting Area charts in excel sheet using XlsxWriter module
- Python | Plotting bar charts in excel sheet using XlsxWriter module
- Python | Plotting Radar charts in excel sheet using XlsxWriter module
- Python | Generate QR Code using pyqrcode module
- Python | Plotting Doughnut charts in excel sheet using XlsxWriter module
- Python | Launch a Web Browser using webbrowser module
- Operations on Graph and Special Graphs using Networkx module | Python
- Hyperlink Induced Topic Search (HITS) Algorithm using Networxx Module | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

