Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from PyRTF import *
- def MakeExample() :
- doc = Document()
- ss = doc.StyleSheet
- section = Section()
- doc.Sections.append(section)
- result = doc.StyleSheet
- NormalText = TextStyle(TextPropertySet(result.Fonts.CourierNew,16))
- ps2 = ParagraphStyle('Courier',NormalText.Copy())
- result.ParagraphStyles.append(ps2)
- # And one final one for 11 pt Arial Bold in Red
- NormalText = TextStyle(TextPropertySet(result.Fonts.Arial,22,bold=True,colour=ss.Colours.Red))
- ps2 = ParagraphStyle('ArialBoldRed',NormalText.Copy())
- result.ParagraphStyles.append(ps2)
- p = Paragraph(ss.ParagraphStyles.Heading1)
- p.append('Example Heading 1')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Normal)
- p.append('This is our first test writing to a RTF file. '
- 'This first paragraph is in the preset style called normal '
- 'and any following paragraphs will use this style until we change it.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Normal)
- p.append('It is also possible to provide overrides for element of a style. ',
- 'For example you can change just the font',
- TEXT(' size to 24 point', size=48),
- ' or',
- TEXT(' typeface to Impact', font=ss.Fonts.Impact),
- ' or even more Attributes like',
- TEXT(' BOLD',bold=True),
- TEXT(' or Italic',italic=True),
- TEXT(' or BOTH',bold=True,italic=True),
- '.')
- section.append(p)
- p = Paragraph()
- p.append('This is a new paragraph with the word ',
- TEXT('RED',colour=ss.Colours.Red),
- ' in Red text.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Courier)
- p.append('Now we are using the Courier style at 8 points. '
- 'All subsequent paragraphs will use this style automatically. '
- 'This saves typing and is the default behaviour for RTF documents.',LINE)
- section.append(p)
- p = Paragraph()
- p.append('Also notice that there is a blank line between the previous paragraph ',
- 'and this one. That is because of the "LINE" inline command.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.ArialBoldRed)
- p.append(LINE,'And now we are using the ArialBoldRed style.',LINE)
- section.append(p)
- return doc
- def OpenFile(name) :
- return file('%s.rtf' % name, 'w')
- if __name__ == '__main__' :
- DR = Renderer()
- doc = MakeExample()
- DR.Write(doc, OpenFile('rtfteste'))
- print "Finished"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement