import os
import docx2pdf

def docx_to_pdf():
    file_path = r'C:\Users\gaodi\Desktop\111'
    for file in os.listdir(file_path):
        print(file)
        suff_name=os.path.splitext(file)[1]
        if suff_name != '.docx':       #扩展名非docx时python库会报错
            continue
        docx_name = file_path + '\\' + file
        pdf_name = docx_name.replace(".docx", ".pdf")
        docx2pdf.convert(docx_name, pdf_name)

if __name__ == '__main__':
    docx_to_pdf()

只能转docx格式的,不支持doc