python安装reportlab
pip install reportlab -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# -*- 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/itBlogToYpl/p/13375637.html