from win32com.client import Dispatch,constants,gencache
#确定源文件和生成文件的路径
docx_path = r’C:\Users\Polyxena\Desktop\untitled1\changhenge.docx’
pdf_path = r’C:\Users\Polyxena\Desktop\untitled1\changhenge5.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)