image图片转pdf

末蓝、 2022-12-09 02:46 324阅读 0赞
  1. from PIL import Image
  2. import os
  3. def image2pdf(file, save_file):
  4. img = Image.open(file)
  5. im_list = []
  6. if img.mode == "RGBA":
  7. img = img.convert('RGB')
  8. im_list.append(img)
  9. img.save(save_file, "PDF", resolution=100.0, save_all=True, append_images=im_list)
  10. print("输出文件名称:", save_file)
  11. if __name__ == '__main__':
  12. in_path = "images/"
  13. out_path = "result/"
  14. if not os.path.exists(out_path): os.mkdir(out_path)
  15. for file in os.listdir(in_path):
  16. image2pdf(f"{in_path}{file}", out_path+file[:-3]+"pdf")

发表评论

表情:
评论列表 (有 0 条评论,324人围观)

还没有评论,来说两句吧...

相关阅读