python3如何将docx转换成pdf文件
本文实例为大家分享了python3将docx转换成pdf文件的具体代码,供大家参考,具体内容如下
直接上代码
# -*- encoding:utf-8 -*- """ author:lgh """ from win32com.client import Dispatch, constants, gencache def doc2pdf(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) return True except: return False finally: w.Quit(constants.wdDoNotSaveChanges) def GenerateSupport(): gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4) def main(): input = r'xxx\xxx.docx' output = r'xxx\xxx.pdf' # GenerateSupport() rc = doc2pdf(input, output) if rc: print('转换成功') else: print('转换失败') if __name__ == '__main__': main()
相关推荐
huha 2020-10-16
TLROJE 2020-10-26
echoes 2020-08-20
nercon 2020-08-01
zhanghaibing00 2020-06-28
Aveiox 2020-06-25
henryzhihua 2020-06-21
zhoutaifeng 2020-06-17
liangzhouqu 2020-06-16
TONIYH 2020-06-11
开心就好 2020-06-10
x青年欢乐多 2020-06-06
KyrieHe 2020-06-03
bertzhang 2020-06-02
haokele 2020-05-29
niehanmin 2020-05-28
davidliu00 2020-05-26