# -*- coding:utf-8 -*-

import os
import time
from docx2pdf import convert
import win32com.client
from concurrent.futures import ProcessPoolExecutor
from multiprocessing import Process
import pythoncom


def convert_word_to_pdf(input_file):
    output_file = input_file.replace('.docx', '.pdf')
    word = win32com.client.Dispatch("Word.Application")
    word.Visible = False 
    doc = word.Documents.Open(input_file)
    doc.SaveAs(output_file, FileFormat=17) 
    doc.Close()
    word.Quit()

def convert_word_to_pdf2(input_file):
    pythoncom.CoInitialize()
    convert(input_file)
    pythoncom.CoUninitialize()

if __name__ == '__main__':
    import os
    files = os.listdir(r"C:\Users\86131\Desktop\回收\潘资料")
    print(files)

    t = time.time()
    p_lists = []
    for file in files:
        p1 = Process(target=convert_word_to_pdf2, args=(r"C:\\Users\\86131\\Desktop\\回收\\潘资料\\"+file,))
        p1.start()
        p_lists.append(p1)

    for p in p_lists:
        p.join()

    print(time.time() - t)