安装:pip install reportlab -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
# -*- coding: utf-8 -*-
from reportlab.lib.pagesizes import portrait
from reportlab.pdfgen import canvas
from PIL import Image
def jpg_to_pdf(jpg_path, pdf_path):
(max_w, max_h) = Image.open(jpg_path).size
user = canvas.Canvas(pdf_path, pagesize=portrait((max_w, max_h)))
user.drawImage(jpg_path, 0, 0, max_w, max_h)
user.showPage()
user.save()
if __name__ == '__main__':
jpg_path = 'thesis1.jpg'
pdf_path = 'thesis2.pdf'
jpg_to_pdf(jpg_path, pdf_path)