Closed lscalese closed 1 year ago
Do you have MS Word installed?
Hello @ubalklen , Thank you for your reply. Yes, MS Word is installed. I don't really understand what's wrong. May be a path problem.
The problem is with these lines :
doc = word.Documents.Open(str(docx_filepath))
print(doc)
# --> None
doc.SaveAs(str(pdf_filepath), FileFormat=wdFormatPDF)
I check the word var :
word = win32com.client.Dispatch("Word.Application")
print(word)
# --> Microsoft Word
The input file exists, If anyone has an idea of the root cause, please leave a comment. Thank you.
Is there any special reason to append things to sys.path
? I don't think it's related to your issue, but that should not be necessary.
The error log shows you are not being able to open the word file. You can try to reproduce the error more closely using pywin32
directly:
import win32com
word = win32com.client.Dispatch("Word.Application")
doc = word.Documents.Open("<path to>ztest.docx")
doc is None
Hi @ubalklen ,
Yes, I added this append due to an error module win32api not being found. I'm sure it's a dirty way to fix it, but I'll try to find another way later.
Thank your for your snippet :
import win32com
word = win32com.client.Dispatch("Word.Application")
doc = word.Documents.Open("<path to>ztest.docx")
doc is None
Indeed, I can reproduce the error, doc is None
.
Maybe a permission issue, but I don't know why. I will do some tests.
Thank you !
I read here: https://stackoverflow.com/questions/61071022/pywintypes-com-error-2147221008-coinitialize-has-not-been-called-none-n that the win32com client cannot initialize itself in every situation. A solution is to give an argument to the Dispatch() function, like in the following example:
import pythoncom
word = win32com.client.Dispatch("Word.Application", pythoncom.CoInitialize())
Hello,Has this issue been resolved? I also encountered the same error.
It's solved thank you!.
@lscalese , How did you solve this issue? I'm having the exact same problem when trying to run docx2pdf as a Windows service.
Could you please tell me how you fixed this?
Hello @jussihi , unfortunately I don't remember exactly... It was a problem on a student project and I just help him to solve it.
I remember It was a security problem with MS-Word fixed in "Local Security Policy" but "what and why" I don't remember :( unfortunately.
@lscalese , I was able to fix the problem by following guidance over https://stackoverflow.com/questions/1006923/automating-office-via-windows-service-on-server-2008?rq=4
Thank you anyways :)
Yes that's it ! Now i see the screen shot I remember.
Glad you fixed your issue :)
IIRC, I had corrected it by adding the argument in bold to the Dispatch function: word = win32com.client.Dispatch("Word.Application", pythoncom.CoInitialize ()) See this page for the hint: https://stackoverflow.com/questions/71292585/python-docx2pdf-attributeerror-open-saveas
Le lun. 26 févr. 2024 à 12:35, Lorenzo Scalese @.***> a écrit :
Yes that's it ! Now i see the screen shot I remember.
Glad you can fix your issue :)
— Reply to this email directly, view it on GitHub https://github.com/AlJohri/docx2pdf/issues/79#issuecomment-1963937261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANRFSO553F5ZRGENTXRCWLYVRXRNAVCNFSM6AAAAAAVKWUY72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTHEZTOMRWGE . You are receiving this because you commented.Message ID: @.***>
Hello, I have an error when I try to convert a document. In a Python shell :
I got the error :
I'm beginner in Python, anyone have idea ? Thank you !
Lorenzo.