python批量把文件html转为pdf或者word文件


import pdfkit
import os
import easygui
import pypandoc

filepath = easygui.diropenbox()

config = pdfkit.configuration(wkhtmltopdf=r'wkhtmltopdf.exe')


#判断文件大小
for curDir, dirs, files in os.walk(filepath):
for file in files:
# print(os.path.join(curDir, file))
if os.path.getsize(os.path.join(curDir, file)) == 0 :
os.remove(os.path.join(curDir, file))
else:
prefix = os.path.splitext(os.path.join(curDir, file))
os.rename(os.path.join(curDir, file),os.path.join(curDir, prefix[0]+".html"))
#转为PDF
pdfkit.from_file(os.path.join(curDir, file), os.path.join(curDir, prefix[0]+".pdf"), configuration=config)
#转为doc
pypandoc.convert_file(os.path.join(curDir, file), 'docx', outputfile=os.path.join(curDir, prefix[0]+".doc"))
上一篇:20210722 Python获取指定文件夹下的文件名的方法


下一篇:ACL和IP prefix-list的区别