How to write RTF from Python?
Erwin S. Andreasen
erwin at andreasen.com
Mon Apr 28 20:48:36 CEST 2003
achrist at easystreet.com writes:
> Any suggestions of the shortest path from a Python program to RTF
> output? RTF seems to be the best (reasonable combination of
> features and compatability) common denominator for exporting
> data so that (windows) users can bring it into their own word
> processing program, whatever that may be. (Any problem with
I have written some code for exporting RTF reports from a web-based
survey/reporting system. It runs on UNIX, so I could not use any COM
objects or similar; the RTF code was generated by hand. Fortunately
the system was designed templatable, so exporting RTF was mostly just
a matter of selecting a set of different style descriptions that
contain RTF instead of HTML.
Others have already linked to the RTF specs. I wrote some basic output
based on that, then we made it nicer using Word. Word's RTF export
exports a lot of unneeded information, so I just cut and pasted the
interesting parts until my output looked right.
Unfortunately Words tends to crash very easily when given an invalid
RTF file. For verifying correctness I used the "ted" editor which is
an ancient RTF-capable graphical UNIX editor. Especially getting
tables displayed right was difficult, the RTF syntax for specifying
them is annoying. ted dumps some debug info when it sees tables it
cannot handle, so that was quite useful.
The RTFDoc.py file from the ptommi project looks like it holds very
useful information; I wish I had found it a few months ago :)
Next step is generating Power Point documents (I found a spec on
wotsit.org and I guess I'll have to wrap some OLE library (cole or
gnome's) and see if I can generate something useful).
<erwin at andreasen.org> Herlev, Denmark
More information about the Python-list