0

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()
jabba
  • 503
  • 2
  • 6
  • 14
  • Just to confirm - you have made sure that it's not just those "first couple of files" that take a while to process right? Try removing those from the processing queue and starting from other files - do you still notice the issue? If not, you can chalk it down to those files being larger and more complex than the other files. – Wiggy A. Jul 21 '20 at 09:11
  • these files are exactly the same - the code is preparing some letters to cilents and that is why I want them to be stored as PDF. The code is launched within GUI, may that be a reason? – jabba Jul 21 '20 at 09:13
  • Not sure, but I doubt it. Stuff like this usually occurs due to infrastructure related issues. If your files are stored/written on/to a hard drive, have you checked if it might have something to do with that particular drive? Something like this perhaps - https://superuser.com/questions/1212753/hard-disk-goes-slow-after-idle-time. – Wiggy A. Jul 21 '20 at 09:26

0 Answers0