def docx_to_pdf(infile,outfile): import os import sys import comtypes.client wdFormatPDF = 17 word = comtypes.client.CreateObject('Word.Application') doc = word.Documents.Open(infile) doc.saveAs(outfile,FileFormat=wdFormatPDF) doc.Close() word.Quit()