利用Python程序实现批量doc文档到pdf的转换

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()

 

posted @ 2018-10-16 16:50  ystwyfe  阅读(669)  评论(0编辑  收藏  举报