阅读背景:

将doc、docx文件转为pdf_李孟笛的博客_doc文件转pdf

来源:互联网 
from win32com import client as wc
import os
# 将doc转pdf
def get_pdf():
    # doc文档对象
    w = wc.Dispatch('Word.Application')
    file_dir = 'D:/需要转换的文件夹路径'
    for root, dirs, files in os.walk(file_dir):
        # print(root)  # 当前目录路径
        # print(dirs)  # 当前路径下所有子目录
        # print(files)  # 当前路径下所有非目录子文件
        for file in files:
            try:
                path = root + '/' + file
                print(file)
                print(path)
                doc = w.Documents.Open(path)
                #将转换好的pdf放入当前目录下的pdf文件夹内
                target_dir = os.getcwd() + '/pdf'
                if not os.path.exists(target_dir):
                    os.makedirs(target_dir)
                file1=file.replace('.docx','').replace('.doc','')
                doc.SaveAs(target_dir+"/from win32com import client as wc
import



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: