# -*- coding: utf-8 -*- import os from win32com.client import Dispatch path = os.getcwd() old_file_path = path + '\\file\\租房合同.docx' new_file_path = path + '\\file\\new_file\\修改为PDf文档的租房合同.pdf' word = Dispatch('word.Application') doc = word.Documents.Open(old_file_path) doc.SaveAs(new_file_path, 17) doc.Close() word.Quit()