|
- import os
- import img2pdf
- path = r'G:\BaiduNetdiskDownload\51-55新旧图片\51-55图片'
- files = os.listdir(path)
- files.sort(key=lambda p:int(p[:-4]))
- name =path+'\\'+path.split('\\')[-1]+'.pdf'
- for file in files:
- A=[os.path.join(path, file) for file in files if file.endswith('.png')]
- with open(name, "wb") as f:
- f.write(img2pdf.convert(A))
复制代码 其中第5行用了一个排序,因为默认排序的时候,01.png,后面是010.png,而不是02.png,所以用了一个sort排序
|
|