Rich Text Format (RTF) Document Generation in Python. To know more about PyRTF click here http://pyrtf.sourceforge.net/
Download
clck here to download pyrtf
Lets dive into the task. For this you need Python,Pyrtf installed in your pc. To install Python just ask google.
To install PyRTF just download from the given link. then unpack it any where then in Linux system open a terminal window go to the unpacked folder location and type python setup.py build
then python setup.py install
this should install PyRTF into your system.
Now I am giving an example where a RTF file can easily be created:
#!/usr/bin/env python
import sys
sys.path.append( ‘../’ )
from PyRTF import *
SIMPLE_TEXT=”this is simple pyrtf example….. hello pyrtf”
def test_rtf_generate():
-
doc = Document()
ss = doc.StyleSheet
section = Section()
doc.Sections.append( section )
-
# text can be added directly to the section
# a paragraph object is create as needed
section.append( ‘Example 1′ )
-
# blank paragraphs are just empty strings
section.append( ” )
-
# a lot of useful documents can be created
# with little more than this
section.append( ‘A lot of useful documents can be created ‘
‘in this way, more advance formating is available ‘
‘but a lot of users just want to see their data come out ‘
‘in something other than a text file.’ )
return doc
def OpenFile( name ) :
-
return file( ‘%s.rtf’ % name, ‘w’ )
if __name__ == ‘__main__’ :
-
print “this is done by Tareq…….”
DR = Renderer()
doc3 = test_rtf_generate()
DR.Write( doc3, OpenFile( ‘myrtf_doc’ ) )
print “Finished”
print “see in the current directory a myrtf_doc.rtf is created!!”
For your information it may cause problem if you just copy paste this code. You better write down in a file. That will make the code run easily. And your programming concept will also be clear by writing code. To learn a Programming language everyone should write down the codes rather than just copy pasting.
let me know if you face any problem running this code. Thanks for reading this.:)
why dont in life do such work.. so that nobody cries?