Install the Pillow library.
pip install Pillow
Now import the Image from PIL. PIL is used for the Pillow library as an alias.
from PIL import Image
Now read the image from the location. In my case “C:\\AiHints” is the location and “cat.png” is the name of the image. Change it according to your image location and name.
image = Image.open("C:\\AiHints\\cat.png")
This code will convert the above png image into a pdf and will save it at the location “C:\\AiHints”.