.doc to pdf using python errors

147 views Asked by At

I'm trying to convert word documents to PDF using python.Currently on python 3.8.

".doc to pdf using python"

import sys                                                                                                   
import os                                                                                                 
import comtypes.client

wdFormatPDF = 17

in_file = os.path.abspath(sys.argv[1])                  
out_file = os.path.abspath(sys.argv[2])

word = comtypes.client.CreateObject('Word.Application')             
doc = word.Documents.Open(in_file)                 
doc.SaveAs(out_file, FileFormat=wdFormatPDF)          
doc.Close()          
word.Quit()

above code answers my question but it works only on my machine when I deploy it onto VM and run it using scheduler remotely, I get below error

File "File Name", line 10, in <module>                                   
word = comtypes.client.CreateObject('Word.Application')
File "Path", init__.py",line1225, in CoCreateInstance
----------------------------------------------------
File"_ctypes/callproc.c",line 930, in getResult
PermissionError:[WinError -2147024891] Access is denied

FYI, word is installed on VM

Thanks

0

There are 0 answers