PyRTF object model

R

Rustom Mody

I am trying to use PyRTF.

I gather that an RTF doc consists of a list of sections, a section
consists of a list of paras,
paras seem to be just text (not sure on that one)

Some questions:

When does one end one section and start another?
How does one handle lists (as in numbered, bulleted etc)?
 
E

Eric Brunel

Rustom Mody said:
I am trying to use PyRTF.

I gather that an RTF doc consists of a list of sections, a section
consists of a list of paras,
paras seem to be just text (not sure on that one)

They also include a style, not only text.
Some questions:

When does one end one section and start another?

You don't 'end a section. You just create a new one and append it to
your document's sections:

my_document = PyRTF.Document()
my_section1 = PyRTF.Section()
my_document.Sections.append(my_section1)
my_section2 = PyRTF.Section()
my_document.Sections.append(my_section2)
How does one handle lists (as in numbered, bulleted etc)?

Not sure on this one. I've had to do it, but could handle it via regular
paragraph style properties and insert the bullets or numbers
explicitely, so I did it just like that. For example, your can create a
PyRTF.ParagraphPropertySet with the options left_indent to 1133 twips =
2cm, first_line_indent to -567 twips = -1cm and set a tab at 1cm with
the option:
tabs=[PyRTF.TabPropertySet(width=567)]
Then you create a PyRTF.ParagraphStyle using this
PyRTF.ParagraphPropertySet and pass it as the first argument when you
create your PyRTF.Paragraph. Then, you just insert tour bullet or number
in the paragraph explicitely, followed by a tab.
There might be a better way to do it.

BTW, as you might have noticed, the documentation for PyRTF is quite
minimal to say the least, so the only way to figure out what can be done
is by reading the PyRTF source codeŠ

HTH
-Eric -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top