from win32com.client import Dispatch, constants, gencache
# 放入要转换的word格式路径
docx_path = r'D:\桌面\示例.docx'
# 放入要导出的pdf格式的路径,并且命名
pdf_path = r'G:\示例.pdf'
# 转换
gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)
wd = Dispatch('Word.Application')
doc = wd.Documents.Open(docx_path, ReadOnly=1)
doc.ExportAsFixedFormat(pdf_path, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup,
CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
wd.Quit(constants.wdDoNotSaveChanges)
只要把代码中的文件存放地址修改一下就可以使用