python3如何将docx转换成pdf文件
本文实例为大家分享了python3将docx转换成pdf文件的具体代码,供大家参考,具体内容如下
直接上代码
#-*-encoding:utf-8-*-
"""
author:lgh
"""
fromwin32com.clientimportDispatch,constants,gencache
defdoc2pdf(input,output):
w=Dispatch('Word.Application')
try:
#打开文件
doc=w.Documents.Open(input,ReadOnly=1)
#转换文件
doc.ExportAsFixedFormat(output,constants.wdExportFormatPDF,
Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
returnTrue
except:
returnFalse
finally:
w.Quit(constants.wdDoNotSaveChanges)
defGenerateSupport():
gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}',0,8,4)
defmain():
input=r'xxx\xxx.docx'
output=r'xxx\xxx.pdf'
#GenerateSupport()
rc=doc2pdf(input,output)
ifrc:
print('转换成功')
else:
print('转换失败')
if__name__=='__main__':
main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短