TGViewer
پایتون | Data Science | Machine Learning پایتون | Data Science | Machine Learning @python4all_pro · 24.2K subscribers
Post #95 5.66K
How to convert image to pdf in Python

# 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 = "Input.png"
 
# storing pdf path
pdf_path = "file_pdf.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")

pip3 install pillow && pip3 install img2pdf


#code

🆔 @Python4all_pro
More from @python4all_pro
  1. Oct 6, 2026#ایونت_آنلاین مجازی‌سازی؛ قلب پنهان زیرساخت👀 اگه به شبکه، سرور و زیرساخت علاقه داری، احتم…
  2. Oct 6, 2026🔴🔴ماهی 3 پروژه 20 میلیونی این شغل 60 میلیون بهت درآمد میده ۳۰ نفری که در تیم ما استخدام…
  3. Oct 4, 2026‌🔴 خبر فوری — انتخاب رشته هوشمند و رایگان با «مسیر» 🔥 «مسیر» نرم‌افزار هوشمند و کاملاً ر…
  4. Sep 29, 2026What better way to understand a powerful tool like Claude Code than to build your own vers…
  5. Sep 28, 202625 GitHub Repositories Every Python Developer Should Know! Want to improve your Python ski…
  6. Sep 27, 202640+ FREE Python Books from Amazon! Want to improve your Python skills without spending a f…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →