Converting rtf to pdf using python -


i new python language , given task convert rtf pdf using python. googled , found code- (not rtf pdf) tried working on , changed according requirement. not able solve it.

i have used below code:

import sys import os import comtypes.client #import win32com.client rtfformatpdf = 17  in_file = os.path.abspath(sys.argv[1]) out_file = os.path.abspath(sys.argv[2])  rtf= comtypes.client.createobject('rtf.application')  rtf.visible = true doc = rtf.documents.open(in_file) doc.saveas(out_file, fileformat=rtfformatpdf) doc.close() rtf.quit() 

but throwing below error

traceback (most recent call last):   file "c:/python34/lib/idlelib/rtf_to_pdf.py", line 12, in <module>     word = comtypes.client.createobject('rtf.application')   file "c:\python34\lib\site-packages\comtypes\client\__init__.py", line 227, in createobject     clsid = comtypes.guid.from_progid(progid)   file "c:\python34\lib\site-packages\comtypes\guid.py", line 78, in from_progid     _clsidfromprogid(str(progid), byref(inst))   file "_ctypes/callproc.c", line 920, in getresult oserror: [winerror -2147221005] invalid class string 

can me this? appreciate if can find better , fast way of doing it. have around 200,000 files convert.

anisha

i used marks's advice , changed word.application , source pointing rtf files. works perfectly! - process slow still faster java application team using. have attached final code in question.

final code: got done using code works word application :

import sys import os,os.path import comtypes.client  wdformatpdf = 17  input_dir = 'input directory' output_dir = 'output directory'  subdir, dirs, files in os.walk(input_dir):     file in files:         in_file = os.path.join(subdir, file)         output_file = file.split('.')[0]         out_file = output_dir+output_file+'.pdf'         word = comtypes.client.createobject('word.application')          doc = word.documents.open(in_file)         doc.saveas(out_file, fileformat=wdformatpdf)         doc.close()         word.quit() 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -