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

python批量把文件html转为pdf或者word文件,第1张

概述importpdfkitimportosimporteasyguiimportpypandocfilepath=easygui.diropenbox()config=pdfkit.configuration(wkhtmltopdf=r'wkhtmltopdf.exe')#判断文件大小forcurDir,dirs,filesinos.walk(filepath):forfileinfiles:#print(os.path.join

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"))
总结

以上是内存溢出为你收集整理的python批量把文件html转为pdf或者word文件全部内容,希望文章能够帮你解决python批量把文件html转为pdf或者word文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1186718.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存