
正文
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()






