word doc转pdf

 

 


from win32com.client import constants, gencache

# TODO pip install pywin32 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
wordPath = r"D:\Download\grafana+influx+jmeter.docx"
pdfPath = r"D:\Download\grafana+influx+jmeter.pdf"


def create_pdf():
"""
word转pdf
:param wordPath: word文件路径
:param pdfPath: 生成pdf文件路径
"""
word = gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open(wordPath, ReadOnly=1)
doc.ExportAsFixedFormat(pdfPath,
constants.wdExportFormatPDF,
Item=constants.wdExportDocumentWithMarkup,
CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
word.Quit(constants.wdDoNotSaveChanges)


if __name__ == '__main__':
create_pdf()
posted @ 2020-02-06 20:03  不带R的墨菲特  阅读(393)  评论(0)    收藏  举报