import os
import comtypes.client
folder = r'doc文档所在文件夹路径'
for dirpath, dirnames, filenames in os.walk(folder):
for file in filenames:
fullpath = os.path.join(dirpath, file)
print(fullpath)
wdFormatPDF = 17 # 保存格式
in_file = fullpath
out_file = fullpath.replace('.doc', '.pdf') # 将doc后缀换成pdf
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()