I'm having some code that loops through word files and saves them to PDF. In general it works fine - no error is thrown but the thing is that a couple of first files are processed for 2-3mins each, then it goes smoothly. Do you have any ideas what may be the reason?
The code is converted to .exe file using pyinstaller and is run within GUI based on wxPython
Here's the code:
word = win32com.client.Dispatch("Word.Application")
for filename in os.listdir(pdfPath):
try:
if filename.endswith((".docx")):
word.Visible = False
wordDoc = word.Documents.Open(pdfPath1 + '\\' + filename, False, False, False)
wordDoc.SaveAs2(pdfPath1 + '\PDF\\' + filename[:len(filename) - 5] + '.pdf', FileFormat=17)
wordDoc.Close()
except Exception as e:
print(e)
word.Quit()