I use Python 3.6 and Django 1.11. I created a Word document with MailMerge and it was ok. Right now I need to save this document as a pdf document.
import win32com.client as win32
from os import path
word = win32.DispatchEx("Word.Application")
filedoc='c:\\growthtech\\Capturar6.docx'
filepdf='c:\\growthtech\\Capturar6.pdf'
in_file = path.abspath(filedoc)
out_file = path.abspath(filepdf)
doc = word.Documents.Open(in_file, 'rb')
doc.SaveAs(new_file, FileFormat=17)
doc.Close()
word.Quit()
It occurred the error bellow in line "doc = word.Documents.Open(in_file, 'rb')".
>>> doc = word.Documents.Open(in_file, 'rb')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<COMObject <unknown>>", line 8, in Open
pywintypes.com_error: (-2147352571, 'Tipo não correspondente.', None, 2)
I appreciate any help.