用Python将多张图片合并成一PDF文件
pip install fpdf
pip install PIL
放码过来
python">from fpdf import FPDFfrom PIL import Image
import os
def makePdf(pdfFileName, listPages):
cover = Image.open(listPages[0])
width, height = cover.size
pdf = 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文件 的全部内容, 来源链接: utcz.com/z/513220.html