I'm trying to open some rtf files to Word and then save as PDFs.
I'm running Windows 10 65 bit -- Word 2016 is installed on my computer.
Python 3.6.0
import os,os.path
import img2pdf
import win32com.client
input_dir = "G:/MHOShare/MHO Staff/James Holland/TempDump/CindyTest/RTFtest"
output_dir = "G:/MHOShare/MHO Staff/James Holland/TempDump/CindyTest/RTFtest"
os.chdir(input_dir)
wdFormatPDF = 17
rtfList = [i for i in os.listdir() if i.endswith(".rtf")]
file = rtfList[0]
word = win32com.client.Dispatch('Word.Application')
word.Visible = False
doc = word.Documents.Open(input_dir + '/' + file)
doc.SaveAs(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF)
doc.close()
However, I get this error.
Traceback (most recent call last):
File "<ipython-input-17-e8d4aaddfc8f>", line 15, in <module>
doc.SaveAs2(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF)
File
"C:\Users\CMTHOL~1\AppData\Local\Temp\gen_py\3.6\00020905-0000-0000-C000-000000000046x0x8x7\_Document.py",
line 461, in SaveAs2
, CompatibilityMode)
com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command
failed', 'wdmain11.chm', 36966, -2146824090), None)
Everything I've read about wdamin11.chm seems to be regarding Word 2007.
This is my first go around with pywin32 so sorry if this is an older issue
(couldn't find a solution on Stackoverflow).
~James
James Holland | Data Analyst | Horizon Health Mental Health Outcomes |
[email protected]<mailto:[email protected]> |
800.266.4440 | 1965 Lakepointe Dr Lewisville TX 75057
UHS of Delaware, Inc. Confidentiality Notice: This e-mail message, including
any attachments, is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review, use,
disclosure or distribution of this information is prohibited, and may be
punishable by law. If this was sent to you in error, please notify the sender
by reply e-mail and destroy all copies of the original message.
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32