I am using Python 2.7.14.
I am currently working on a program that makes adjustments to certain information on a word document. This goal has been achieved however I am facing troubles converting the .docx document into a .pdf.
I would like to use the code in this link: .doc to pdf using python
However I am getting an error when importing comtypes.client
Traceback (most recent call last):
File "C:\Python27\comtypes.py", line 2, in <module>
from comtypes.client import CreateObject, GetActiveObject
File "C:\Python27\comtypes.py", line 2, in <module>
from comtypes.client import CreateObject, GetActiveObject
ImportError: No module named client
It does look like I have installed comtypes using pip install comtypes
.
This is the code I would like to use to convert my docx into pdf and also where I am encountering an error.
Appreciate any advice.
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()