python怎么变成文档_python3如何将docx转换成pdf文件
本文實(shí)例為大家分享了python3將docx轉(zhuǎn)換成pdf文件的具體代碼,供大家參考,具體內(nèi)容如下
直接上代碼
# -*- 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)
# 轉(zhuǎn)換文件
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('轉(zhuǎn)換成功')
else:
print('轉(zhuǎn)換失敗')
if __name__ == '__main__':
main()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持聚米學(xué)院。
總結(jié)
以上是生活随笔為你收集整理的python怎么变成文档_python3如何将docx转换成pdf文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java if在内存中_全面理解Java
- 下一篇: 逻辑判断 java_写 JS 逻辑判断,