以上不用介绍了,直接上代码,如下:
# -*- coding: UTF-8 -*-
import sys
from reportlab.lib.pagesizes import portrait
from reportlab.pdfgen import canvas
from PIL import Image
def imgtopdf(input_paths, outputpath):
(maxw, maxh) = Image.open(input_paths).size
c = canvas.Canvas(outputpath, pagesize=portrait((maxw, maxh)))
c.drawImage(input_paths, 0, 0, maxw, maxh)
c.showPage()
c.save()
# 调用demo:
imgtopdf("D:\XY1700054820171104.png", "cc.pdf")