![](https://img2018.cnblogs.com/i-beta/1633019/202002/1633019-20200206200245629-2034174998.png)
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:Downloadgrafana+influx+jmeter.docx"
pdfPath = r"D:Downloadgrafana+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()