用Python将多张图片合并成一PDF文件
生活随笔
收集整理的這篇文章主要介紹了
用Python将多张图片合并成一PDF文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先前條件
需要安裝兩模塊:fpdf、PIL
- pip install fpdf
- pip install PIL
放碼過來
from fpdf import FPDF from PIL import Image import osdef makePdf(pdfFileName, listPages):cover = Image.open(listPages[0])width, height = cover.sizepdf = FPDF(unit = "pt", format = [width, height])for page in listPages:pdf.add_page()pdf.image(page, 0, 0)pdf.output(pdfFileName, "F")makePdf("result.pdf", [imgFileName for imgFileName in os.listdir('.') \if imgFileName.endswith("png")])參考文獻
Create PDF from a list of images
總結
以上是生活随笔為你收集整理的用Python将多张图片合并成一PDF文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装惠普M1136打印机一直处于“新设备
- 下一篇: python数字1 3怎么表示_Pyth