1. 程式人生 > >python圖片轉pdf

python圖片轉pdf

以上不用介紹了,直接上程式碼,如下:

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