Python: Word to Pdf error (OSError: [WinError -2147221005] Invalid class string )

660 Views Asked by At

i'm trying to conver word file into pdf file with this code: but it gives me the this not understood error (OSError: [WinError -2147221005] Invalid class string) I checked this answer but I didn't understand the answer

import os
import comtypes.client

wdFormatPDF = 17



in_file = os.path.abspath("C:\\Users\\somename\\Desktop\\tests\\sad.doc")
out_file = os.path.abspath("C:\\Users\\somename\\Desktop\\tests\\sad.pdf")

word = comtypes.client.CreateObject('Word.Application')

doc = word.Documents.Open(in_file)

doc.SaveAs(out_file, FileFormat=wdFormatPDF)

doc.Close()

word.Quit() 
0

There are 0 best solutions below