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 婆婆高寿祝福语大全简短