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//')

 

posted on 2018-11-14 11:22  奔跑吧,蜗牛!  阅读(1234)  评论(0编辑  收藏

导航

统计