diff --git a/module/worker.py b/module/worker.py index cf092fc..6afc531 100644 --- a/module/worker.py +++ b/module/worker.py @@ -1,6 +1,7 @@ import os import traceback +import pythoncom from PySide6.QtCore import QObject, Signal from win32com import client @@ -52,11 +53,14 @@ class DTGWorker(QObject): if os.path.exists(pdf_file): os.remove(pdf_file) - word = client.Dispatch("Word.Application") - doc = word.Documents.Open(word_file) - doc.SaveAs(pdf_file, 17) - doc.Close() - word.Quit() + # https://stackoverflow.com/questions/71292585/python-docx2pdf-attributeerror-open-saveas + word = client.Dispatch("Word.Application", pythoncom.CoInitialize()) + try: + doc = word.Documents.Open(word_file) + doc.SaveAs(pdf_file, 17) + doc.Close() + finally: + word.Quit() os.remove(word_file) os.startfile(pdf_file)