How to write RTF from Python?

achrist at easystreet.com achrist at easystreet.com
Sat Apr 26 01:06:27 EDT 2003


kkennedy wrote:
> 
> RTF format (MS open format???) is a moving target.  RTF files created
> by MS Word 97 will look odd or worse in MS Word 95, and be completely
> unreadable in WordPad. Either find out what version of RTF WordPad
> uses and use that, or require your users to have a specific version
> of MS Word (or the free download - MS Word viewer).
> 

That's one reason why I asked if there were any solutions already
available.  If someone had already identified the forms of rtf 
markup that worked well in all those versions, I would not want 
to rediscover the same set of tires.  

> why do your users have to open the document in a word processor if
> it isn't going to be edited?  

OK.  I'll give you an A for deduction.  It is going to be edited.  
I'm generating boilerplate.  User gets to customize.  I should hope
that I don't need to dictate specific word-processor to users. MS
Word may be the most common, but there are many versions, and I have
no reason to favor any particular vendor as they have never
particularly favored me.  I would recommend Abiword as a free 90%
solution for someone who didn't have a word-processor, but I'd like
to make a file that looks better than Ascii that the people with
MS-Works or Corel are who-knows-what will also be able to deal with.

I suppose that if I could use COM to grab the RTF control that comes
with windows, that might be the best way to create an RTF file that
would work on the same machine, but IDK.  And I have no idea if or
where I can get documentation of the API for that RTF COM object, and
I do remember that there are two versions of the MS RTF  dll, too.
My objectives are limited, so now I'm just starting with output from
a simple RTF editor and trying to pick it apart into  templates for
my Python code to fill in.  Maybe that will work, but I think that
there are a few tricks, I'm not sure.  I did something like this to
generate RTF from C++ a few years back, but what we did was very
simple and didn't generate much markup, mostly fixed-font text. I'd
figure that there's a better way someone has worked out.


Al




More information about the Python-list mailing list