Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pywintypes.com_error saving word doc as pdf python pywin32

I am opening a word document in word using python and trying to convert it using this answer on StackOverflow.

My python code:

import win32com.client

word = win32com.client.Dispatch('Word.Application')
wdFormatPDF = 17
doc = word.Documents.Open(path)
doc.SaveAs(file_name, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()

However, when doing so, I am met with this error:

doc.SaveAs(file_name, FileFormat=wdFormatPDF)
  File "<COMObject Open>", line 5, in SaveAs
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None)

Please can you explain what this error means and how to fix my code.

like image 231
koder613 Avatar asked Sep 28 '26 08:09

koder613


1 Answers

I had the same error. In my case, I did not have write permissions in the directory I was saving to.

See also: Error pywintypes.com_error occur when convert files docx to files pdf

like image 173
leducvin Avatar answered Sep 30 '26 01:09

leducvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!