Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from PyRTF import *
- def FabriqueExemple():
- docu = Document()
- ss = docu.StyleSheet
- section = Section()
- docu.Sections.append(section)
- result = docu.StyleSheet
- NormalText = TextStyle(TextPropertySet(result.Fonts.CourierNew,16))
- ps2 = ParagraphStyle('Courier',NormalText.Copy())
- result.ParagraphStyles.append(ps2)
- # et le tout dernier pour l'Arial Gras Rouge en 11 points
- TexteNormal = TextStyle(TextPropertySet(result.Fonts.Arial,22,bold=True,colour=ss.Colours.Red))
- ps2 = ParagraphStyle('ArialGrasRouge',TexteNormal.Copy())
- result.ParagraphStyles.append(ps2)
- p = Paragraph(ss.ParagraphStyles.Heading1)
- p.append('Exemple d''en-tete')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Normal)
- p.append('Voici notre premier exemple de creation de fichier RTF. '
- 'Ce premier paragraphe est dans le style predefini appele normal '
- 'et tous les paragraphes suivants utiliseront ce style sauf si on le change.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Normal)
- p.append( 'Il est aussi possible de passer outre les elements d''un style. ',
- 'Par exemple vous pouvez modifier seulement la ',
- TEXT(' taille de la police a 24 points', size=48),
- ' ou',
- TEXT(' son type a Impact', font=ss.Fonts.Impact),
- ' ou meme modifier d''autres attributs comme',
- TEXT(' la graisse ',bold=True),
- TEXT(' ou l''italique',italic=True),
- TEXT(' ou les deux',bold=True,italic=True),
- '.' )
- section.append(p)
- p = Paragraph()
- p.append('Voici un nouveau paragraphe avec le mot ',
- TEXT('ROUGE',colour=ss.Colours.Red),
- ' ecrit en rouge.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.Courier)
- p.append('Maintenant on utilise le style Courier en 8 points. '
- 'Tous les paragraphes suivants utiliseront ce style automatiquement. '
- 'Ceci evite de resaisir du code et est le comportement par defaut pour les documents RTF.',LINE)
- section.append(p)
- p = Paragraph()
- p.append('Remarquez aussi qu''il y a une ligne blanche entre le paragraphe precedent ',
- 'et celui-ci. C''est a cause de la commande en ligne LINE.')
- section.append(p)
- p = Paragraph(ss.ParagraphStyles.ArialGrasRouge)
- p.append(LINE,'Et maintenant on utilise le style ArialGrasRouge.',LINE)
- section.append(p)
- return docu
- def OuvreFichier(nom) :
- return file('%s.rtf' % nom, 'w')
- if __name__ == '__main__' :
- DR = Renderer()
- docu = FabriqueExemple()
- DR.Write(docu, OuvreFichier('rtftesta'))
- print "Fini"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement