1. 程式人生 > >Python庫之img2pdf 小試牛刀

Python庫之img2pdf 小試牛刀

批量處理PNG圖片合成pdf

 

#/home/liq-n/桌面/png
import os
import img2pdf

def doImg2Pdf(fileName):
    with open("output.pdf", "wb") as f:
        #fileList = os.listdir('//home//Desktop//')
        fileList = os.listdir(fileName)
        pngList = []
        for pngName in range(488,492):
           # pngName =  "//home//Desktop//%s.PNG" % str(pngName);
pngName = "%s%s.PNG" % (fileName, str(pngName)); pngList.append(pngName) pfn_bytes = img2pdf.convert(pngList) f.write(pfn_bytes) print("轉換完成") doImg2Pdf('//home//liq-n//Desktop//')