CSDN博客地址

Python-将图片转成pdf文件

# -*- 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)

 

posted @ 2020-06-22 19:40  Yi_warmth  阅读(4173)  评论(1编辑  收藏  举报
CSDN博客地址