0

I made a simple shortcut program which basically converts a *.docx file into a pdf and then uploads it to a website. Here's how the conversion is executed:

import win32com.client

outputFilePath = os.path.dirname(os.path.realpath(__file__)) + "\\pdf\\" + fileName + ".pdf"

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

After compiling the code into an executable file, it works perfectly fine on the machine I've written this on and on my laptop as well. However, I need this to work on another computer which when attempts to run this script, displays the following message instead:

File "<COMObject Open>", line 8, in SaveAs
pywintypes.com_error: (-2147352567, 'Eccezione.', (0, 'Microsoft Word', 'Comando fallito', 'C:\\Program Files (x86)\\Microsoft Office\\Office12\\1040\\WDMAIN11.CHM', 36966, -2146824090), None)

What might be causing this?

Gian
  • 327
  • 2
  • 8
  • 1
    It looks like your target machine has a different, older version of Word installed. But this answer from GitHub: https://github.com/enthought/comtypes/issues/142 suggests there is a download to make it work on MS Office 2007. – BoarGules Mar 22 '20 at 11:25
  • it may be also caused if the folder `pdf` does not exist – Vova Mar 22 '20 at 11:36
  • @BoarGules so the problem is basically that older versions of Office didn't come pre-packaged with a utility to save files as PDF. That solution seems like it might work, but the official download for "Microsoft Save as PDF o XPS" doesn't exist anymore. The only unofficial download I was able to found for this is on filehippo, about which I've read rather mixed opinions about. Is there any alternative to just upgrading Office to a more recent version? – Gian Mar 22 '20 at 18:29
  • I'm not sufficiently expert in Word to answer that. You could install a PDF printer driver (application thinks it is printing but the driver creates a PDF instead). Then you're not dependent on Word's Save As functionality. – BoarGules Mar 22 '20 at 18:34

0 Answers0