reportlab/platypus/layout.py
changeset 221 3d71b66b14c6
parent 212 b04e22acb4fa
child 226 a9acb67cdef7
equal deleted inserted replaced
220:3b27693ac273 221:3d71b66b14c6
    29 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    29 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    30 # PERFORMANCE OF THIS SOFTWARE.
    30 # PERFORMANCE OF THIS SOFTWARE.
    31 #
    31 #
    32 ###############################################################################
    32 ###############################################################################
    33 #	$Log: layout.py,v $
    33 #	$Log: layout.py,v $
       
    34 #	Revision 1.26  2000/05/16 16:15:16  rgbecker
       
    35 #	Changes related to removal of SimpleFlowDocument
       
    36 #
    34 #	Revision 1.25  2000/05/15 13:36:11  rgbecker
    37 #	Revision 1.25  2000/05/15 13:36:11  rgbecker
    35 #	Splitting changes
    38 #	Splitting changes
    36 #
    39 #	
    37 #	Revision 1.24  2000/05/12 12:52:00  rgbecker
    40 #	Revision 1.24  2000/05/12 12:52:00  rgbecker
    38 #	Fixes to BasicFrame split method
    41 #	Fixes to BasicFrame split method
    39 #	
    42 #	
    40 #	Revision 1.23  2000/05/11 14:02:14  rgbecker
    43 #	Revision 1.23  2000/05/11 14:02:14  rgbecker
    41 #	Removed usage of spaceBefore/After in wrap methods
    44 #	Removed usage of spaceBefore/After in wrap methods
   102 #	License text fixes
   105 #	License text fixes
   103 #	
   106 #	
   104 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
   107 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
   105 #	Added license, __version__ and Logi comment
   108 #	Added license, __version__ and Logi comment
   106 #	
   109 #	
   107 __version__=''' $Id: layout.py,v 1.25 2000/05/15 13:36:11 rgbecker Exp $ '''
   110 __version__=''' $Id: layout.py,v 1.26 2000/05/16 16:15:16 rgbecker Exp $ '''
   108 __doc__="""
   111 __doc__="""
   109 Page Layout And TYPography Using Scripts
   112 Page Layout And TYPography Using Scripts
   110 a page layout API on top of PDFgen
   113 a page layout API on top of PDFgen
   111 currently working on paragraph wrapping stuff.
   114 currently working on paragraph wrapping stuff.
   112 """
   115 """
   540 			frame.addFromList(flowables)
   543 			frame.addFromList(flowables)
   541 
   544 
   542 			#print 'drew page %d, %d objects remaining' % (self.page, len(flowables))
   545 			#print 'drew page %d, %d objects remaining' % (self.page, len(flowables))
   543 
   546 
   544 		canv.save()
   547 		canv.save()
   545 	##########################################################
       
   546 	##
       
   547 	##	 testing
       
   548 	##
       
   549 	##########################################################
       
   550 
       
   551 def randomText():
       
   552 	#this may or may not be appropriate in your company
       
   553 	from random import randint, choice
       
   554 
       
   555 	RANDOMWORDS = ['strategic','direction','proactive',
       
   556 	'reengineering','forecast','resources',
       
   557 	'forward-thinking','profit','growth','doubletalk',
       
   558 	'venture capital','IPO']
       
   559 
       
   560 	sentences = 5
       
   561 	output = ""
       
   562 	for sentenceno in range(randint(1,5)):
       
   563 		output = output + 'Blah'
       
   564 		for wordno in range(randint(10,25)):
       
   565 			if randint(0,4)==0:
       
   566 				word = choice(RANDOMWORDS)
       
   567 			else:
       
   568 				word = 'blah'
       
   569 			output = output + ' ' +word
       
   570 		output = output+'.'
       
   571 	return output
       
   572 
       
   573 def myFirstPage(canvas, doc):
       
   574 	canvas.saveState()
       
   575 	canvas.setStrokeColor(red)
       
   576 	canvas.setLineWidth(5)
       
   577 	canvas.line(66,72,66,PAGE_HEIGHT-72)
       
   578 	canvas.setFont('Times-Bold',24)
       
   579 	canvas.drawString(108, PAGE_HEIGHT-108, "PLATYPUS")
       
   580 	canvas.setFont('Times-Roman',12)
       
   581 	canvas.drawString(4 * inch, 0.75 * inch, "First Page")
       
   582 	canvas.restoreState()
       
   583 
       
   584 def myLaterPages(canvas, doc):
       
   585 	#canvas.drawImage("snkanim.gif", 36, 36)
       
   586 	canvas.saveState()
       
   587 	canvas.setStrokeColor(red)
       
   588 	canvas.setLineWidth(5)
       
   589 	canvas.line(66,72,66,PAGE_HEIGHT-72)
       
   590 	canvas.setFont('Times-Roman',12)
       
   591 	canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
       
   592 	canvas.restoreState()
       
   593 
       
   594 def run():
       
   595 	objects_to_draw = []
       
   596 	from reportlab.lib.styles import ParagraphStyle
       
   597 	from reportlab.platypus.paragraph import Paragraph
       
   598 
       
   599 	#need a style
       
   600 	normal = ParagraphStyle('normal')
       
   601 	normal.firstLineIndent = 18
       
   602 	normal.spaceBefore = 6
       
   603 	import random
       
   604 	for i in range(15):
       
   605 		height = 0.5 + (2*random.random())
       
   606 		box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
       
   607 		objects_to_draw.append(box)
       
   608 		para = Paragraph(randomText(), normal)
       
   609 		objects_to_draw.append(para)
       
   610 
       
   611 	doc = SimpleFlowDocument('platypus.pdf',DEFAULT_PAGE_SIZE)
       
   612 	doc.onFirstPage = myFirstPage
       
   613 	doc.onNewPage = myLaterPages
       
   614 	doc.build(objects_to_draw)
       
   615 
       
   616 if __name__ == '__main__':
       
   617 	run()