examples2.py :  » Development » PyRTF » PyRTF-0.45 » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » PyRTF 
PyRTF » PyRTF 0.45 » examples » examples2.py
import os
import sys
sys.path.append( '../' )

from PyRTF import *

def MakeExample1() :
  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( 'Image Example 1' )

  section.append( 'You can add images in one of two ways, either converting the '
          'image each and every time like;' )

  image = Image( 'image.jpg' )
  section.append( Paragraph( image ) )

  section.append( 'Or you can use the image object to convert the image and then '
          'save it to a raw code element that can be included later.' )

  fout = file( 'image_tmp.py', 'w' )
  print >> fout, 'from PyRTF import RawCode'
  print >> fout
  fout.write( image.ToRawCode( 'TEST_IMAGE' ) )
  fout.close()

  import image_tmp
  section.append( Paragraph( image_tmp.TEST_IMAGE ) )
  section.append( 'Have a look in image_tmp.py for the converted RawCode.' )

  section.append( 'here are some png files' )
  for f in [ 'img1.png',
         'img2.png',
         'img3.png',
         'img4.png' ] :
    section.append( Paragraph( Image( f ) ) )

  return doc

def OpenFile( name ) :
  return file( '%s.rtf' % name, 'w' )

if __name__ == '__main__' :
  DR = Renderer()

  doc1 = MakeExample1()

  DR.Write( doc1, OpenFile( 'Image1' ) )

  print "Finished"

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.