img2pdf
是一个开源Python包,用于将图像转换为pdf格式。它包括另一个模块枕头,也可以用来增强图像(亮度、对比度等)
null
使用此命令安装软件包
pip install img2pdf
以下是实施情况:
图像可以通过以下方式转换为pdf字节: img2pdf.convert()
img2pdf模块提供的函数,然后pdf文件以wb模式打开,并用字节写入。
# 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" ) |
输出:
Successfully made pdf file
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END