Member-only story

Convert an Image to a PDF file using Python

Python Coding
Sep 16, 2024

--

pip install img2pdf

import img2pdf

# Open the image file in binary mode
with open("TVH.png", "rb") as image:

pdf_bytes = img2pdf.convert(image.read())

with open("TVH.pdf", "wb") as pdf:
pdf.write(pdf_bytes)

print("Image has been converted to PDF successfully.")

#source code --> clcoding.com
Image has been converted to PDF successfully

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet