from win32com.client import Dispatch,constants,gencache
docx_path = (r‘C:/Users/13375/Desktop/python/长恨歌.docx‘)
pdf_path = (r‘C:/Users/13375/Desktop/python/长恨歌_pdf.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)
原文:https://www.cnblogs.com/tomhu/p/12342951.html