python使图片转化为pdf
2021-04-09 04:28
标签:pre def can port pat log name image show python使图片转化为pdf 标签:pre def can port pat log name image show 原文地址:https://www.cnblogs.com/itBlogToYpl/p/13375637.html# python安装reportlab
pip install reportlab -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
参考https://blog.csdn.net/zhezhebie/article/details/88846824# -*- coding: utf-8 -*-
from reportlab.lib.pagesizes import portrait
from reportlab.pdfgen import canvas
from PIL import Image
def jpg_to_pdf(jpg, pdf_path):
(w, h) = Image.open(jpg).size
user = canvas.Canvas(pdf_path, pagesize=portrait((w, h)))
user.drawImage(jpg, 0, 0, w, h)
user.showPage()
user.save()
if __name__ == ‘__main__‘:
jpg_path = ‘code.png‘
pdf_path = ‘code.pdf‘
jpg_to_pdf(jpg_path, pdf_path)
# 参考https://www.cnblogs.com/zhouzetian/p/13178749.html
上一篇:python的os命令
下一篇:### python基础小汇总