Added callbacks throughout
authorandy_robinson
Sun, 03 Feb 2002 21:25:57 +0000
changeset 1502 125b52eb0a8e
parent 1501 2dfe5d299bc8
child 1503 ac95035a5835
Added callbacks throughout
reportlab/pdfgen/canvas.py
reportlab/platypus/doctemplate.py
reportlab/test/test_pdfgen_callback.py
reportlab/test/test_pdfgen_general.py
reportlab/test/test_platypus_general.py
--- a/reportlab/pdfgen/canvas.py	Sun Feb 03 20:16:22 2002 +0000
+++ b/reportlab/pdfgen/canvas.py	Sun Feb 03 21:25:57 2002 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/canvas.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/pdfgen/canvas.py,v 1.95 2001/12/19 18:41:00 aaron_watters Exp $
-__version__=''' $Id: canvas.py,v 1.95 2001/12/19 18:41:00 aaron_watters Exp $ '''
+#$Header: /tmp/reportlab/reportlab/pdfgen/canvas.py,v 1.96 2002/02/03 21:25:57 andy_robinson Exp $
+__version__=''' $Id: canvas.py,v 1.96 2002/02/03 21:25:57 andy_robinson Exp $ '''
 __doc__=""" 
 The Canvas object is the primary interface for creating PDF files. See
 doc/userguide.pdf for copious examples.
@@ -118,6 +118,8 @@
         #this only controls whether it prints 'saved ...' - 0 disables
         self._verbosity = verbosity
 
+        #this is called each time a page is output if non-null
+        self._onPage = None
         
         self._pagesize = pagesize
         #self._currentPageHasImages = 0
@@ -353,12 +355,21 @@
         self._setXObjects(page)
         self._setAnnotations(page)
         self._doc.addPage(page)
-        
+
+        if self._onPage:
+            self._onPage(self._pageNumber)
         #now get ready for the next one
         self._pageNumber = self._pageNumber + 1
         self._restartAccumulators()
         self.init_graphics_state()
         self.state_stack = []
+
+    def setPageCallBack(self, func):
+        """func(pageNum) will be called on each page end.
+        
+       This is mainly a hook for progress monitoring.
+        Call setPageCallback(None) to clear a callback."""
+        self._onPage = func
         
     def _setAnnotations(self,page):
         page.Annots = self._annotationrefs
--- a/reportlab/platypus/doctemplate.py	Sun Feb 03 20:16:22 2002 +0000
+++ b/reportlab/platypus/doctemplate.py	Sun Feb 03 21:25:57 2002 +0000
@@ -1,14 +1,14 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.49 2001/11/26 21:49:01 andy_robinson Exp $
+#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.50 2002/02/03 21:25:57 andy_robinson Exp $
 
-__version__=''' $Id: doctemplate.py,v 1.49 2001/11/26 21:49:01 andy_robinson Exp $ '''
+__version__=''' $Id: doctemplate.py,v 1.50 2002/02/03 21:25:57 andy_robinson Exp $ '''
 
 __doc__="""
 This module contains the core structure of platypus.
 
-Platypus constructs documents.	Document styles are determined by DocumentTemplates.
+Platypus constructs documents.  Document styles are determined by DocumentTemplates.
 
 Each DocumentTemplate contains one or more PageTemplates which defines the look of the
 pages of the document.
@@ -40,749 +40,759 @@
 
 
 def _doNothing(canvas, doc):
-	"Dummy callback for onPage"
-	pass
+    "Dummy callback for onPage"
+    pass
 
 
 class IndexingFlowable(Flowable):
-	"""Abstract interface definition for flowables which might
-	hold references to other pages or themselves be targets
-	of cross-references.  XRefStart, XRefDest, Table of Contents,
-	Indexes etc."""
-	def isIndexing(self):
-		return 1
+    """Abstract interface definition for flowables which might
+    hold references to other pages or themselves be targets
+    of cross-references.  XRefStart, XRefDest, Table of Contents,
+    Indexes etc."""
+    def isIndexing(self):
+        return 1
 
-	def isSatisfied(self):
-		return 1
+    def isSatisfied(self):
+        return 1
 
-	def notify(self, kind, stuff):
-		"""This will be called by the framework wherever 'stuff' happens.
-		'kind' will be a value that can be used to decide whether to
-		pay attention or not."""
-		pass
+    def notify(self, kind, stuff):
+        """This will be called by the framework wherever 'stuff' happens.
+        'kind' will be a value that can be used to decide whether to
+        pay attention or not."""
+        pass
 
-	def beforeBuild(self):
-		"""Called by multiBuild before it starts; use this to clear
-		old contents"""
-		pass
+    def beforeBuild(self):
+        """Called by multiBuild before it starts; use this to clear
+        old contents"""
+        pass
 
-	def afterBuild(self):
-		"""Called after build ends but before isSatisfied"""
-		pass
+    def afterBuild(self):
+        """Called after build ends but before isSatisfied"""
+        pass
 
 
 class ActionFlowable(Flowable):
-	'''This Flowable is never drawn, it can be used for data driven controls
-	   For example to change a page template (from one column to two, for example)
-	   use NextPageTemplate which creates an ActionFlowable.
-	'''
-	def __init__(self,action=()):
-		if type(action) not in (ListType, TupleType):
-			action = (action,)
-		self.action = tuple(action)
+    '''This Flowable is never drawn, it can be used for data driven controls
+       For example to change a page template (from one column to two, for example)
+       use NextPageTemplate which creates an ActionFlowable.
+    '''
+    def __init__(self,action=()):
+        if type(action) not in (ListType, TupleType):
+            action = (action,)
+        self.action = tuple(action)
 
-	def wrap(self, availWidth, availHeight):
-		'''Should never be called.'''
-		raise NotImplementedError
+    def wrap(self, availWidth, availHeight):
+        '''Should never be called.'''
+        raise NotImplementedError
 
-	def draw(self):
-		'''Should never be called.'''
-		raise NotImplementedError
+    def draw(self):
+        '''Should never be called.'''
+        raise NotImplementedError
 
-	def apply(self,doc):
-		'''
-		This is called by the doc.build processing to allow the instance to
-		implement its behaviour
-		'''
-		action = self.action[0]
-		args = tuple(self.action[1:])
-		arn = 'handle_'+action
-		try:
-			apply(getattr(doc,arn), args)
-		except AttributeError, aerr:
-			if aerr.args[0]==arn:
-				raise NotImplementedError, "Can't handle ActionFlowable(%s)" % action
-			else:
-				raise
-		except "bogus":
-			t, v, None = sys.exc_info()
-			raise t, "%s\n	 handle_%s args=%s"%(v,action,args)
+    def apply(self,doc):
+        '''
+        This is called by the doc.build processing to allow the instance to
+        implement its behaviour
+        '''
+        action = self.action[0]
+        args = tuple(self.action[1:])
+        arn = 'handle_'+action
+        try:
+            apply(getattr(doc,arn), args)
+        except AttributeError, aerr:
+            if aerr.args[0]==arn:
+                raise NotImplementedError, "Can't handle ActionFlowable(%s)" % action
+            else:
+                raise
+        except "bogus":
+            t, v, None = sys.exc_info()
+            raise t, "%s\n   handle_%s args=%s"%(v,action,args)
 
-	def __call__(self):
-		return self
+    def __call__(self):
+        return self
 
 class NextFrameFlowable(ActionFlowable):
-	def __init__(self,ix,resume=0):
-		ActionFlowable.__init__(self,('nextFrame',ix,resume))
+    def __init__(self,ix,resume=0):
+        ActionFlowable.__init__(self,('nextFrame',ix,resume))
 
 class CurrentFrameFlowable(ActionFlowable):
-	def __init__(self,ix,resume=0):
-		ActionFlowable.__init__(self,('currentFrame',ix,resume))
+    def __init__(self,ix,resume=0):
+        ActionFlowable.__init__(self,('currentFrame',ix,resume))
 
 class _FrameBreak(ActionFlowable):
-	'''
-	A special ActionFlowable that allows setting doc._nextFrameIndex
+    '''
+    A special ActionFlowable that allows setting doc._nextFrameIndex
 
-	eg story.append(FrameBreak('mySpecialFrame'))
-	'''
-	def __call__(self,ix=None,resume=0):
-		r = self.__class__(self.action+(resume,))
-		r._ix = ix
-		return r
+    eg story.append(FrameBreak('mySpecialFrame'))
+    '''
+    def __call__(self,ix=None,resume=0):
+        r = self.__class__(self.action+(resume,))
+        r._ix = ix
+        return r
 
-	def apply(self,doc):
-		if getattr(self,'_ix',None): doc._nextFrameIndex = self._ix
-		ActionFlowable.apply(self,doc)
+    def apply(self,doc):
+        if getattr(self,'_ix',None): doc._nextFrameIndex = self._ix
+        ActionFlowable.apply(self,doc)
 
 FrameBreak = _FrameBreak('frameEnd')
 PageBegin = ActionFlowable('pageBegin')
 
 
 class NextPageTemplate(ActionFlowable):
-	"""When you get to the next page, use the template specified (change to two column, for example)  """
-	def __init__(self,pt):
-		ActionFlowable.__init__(self,('nextPageTemplate',pt))
+    """When you get to the next page, use the template specified (change to two column, for example)  """
+    def __init__(self,pt):
+        ActionFlowable.__init__(self,('nextPageTemplate',pt))
 
 
 class PageTemplate:
-	"""
-	essentially a list of Frames and an onPage routine to call at the start
-	of a page when this is selected. onPageEnd gets called at the end.
-	derived classes can also implement beforeDrawPage and afterDrawPage if they want
-	"""
-	def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing,
-				 pagesize=defaultPageSize):
-		if type(frames) not in (ListType,TupleType): frames = [frames]
-		assert filter(lambda x: not isinstance(x,Frame), frames)==[], "frames argument error"
-		self.id = id
-		self.frames = frames
-		self.onPage = onPage
-		self.onPageEnd = onPageEnd
-		self.pagesize = pagesize
+    """
+    essentially a list of Frames and an onPage routine to call at the start
+    of a page when this is selected. onPageEnd gets called at the end.
+    derived classes can also implement beforeDrawPage and afterDrawPage if they want
+    """
+    def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing,
+                 pagesize=defaultPageSize):
+        if type(frames) not in (ListType,TupleType): frames = [frames]
+        assert filter(lambda x: not isinstance(x,Frame), frames)==[], "frames argument error"
+        self.id = id
+        self.frames = frames
+        self.onPage = onPage
+        self.onPageEnd = onPageEnd
+        self.pagesize = pagesize
 
-	def beforeDrawPage(self,canv,doc):
-		"""Override this if you want additional functionality or prefer
-		a class based page routine.  Called before any flowables for
-		this page are processed."""
-		pass
+    def beforeDrawPage(self,canv,doc):
+        """Override this if you want additional functionality or prefer
+        a class based page routine.  Called before any flowables for
+        this page are processed."""
+        pass
 
-	def checkPageSize(self,canv,doc):
-		'''This gets called by the template framework
-		If canv size != doc size then the canv size is set to
-		the template size or if that's not available to the
-		doc size.
-		'''
-		#### NEVER EVER EVER COMPARE FLOATS FOR EQUALITY
-		#RGB converting pagesizes to ints means we are accurate to one point
-		#RGB I suggest we should be aiming a little better
-		cp = None
-		dp = None
-		sp = None
-		if canv._pagesize: cp = map(int, canv._pagesize)
-		if self.pagesize: sp = map(int, self.pagesize)
-		if doc.pagesize: dp = map(int, doc.pagesize)
-		if cp!=sp:
-			if sp:
-				canv.setPageSize(self.pagesize)
-			elif cp!=dp:
-				canv.setPageSize(doc.pagesize)
+    def checkPageSize(self,canv,doc):
+        '''This gets called by the template framework
+        If canv size != doc size then the canv size is set to
+        the template size or if that's not available to the
+        doc size.
+        '''
+        #### NEVER EVER EVER COMPARE FLOATS FOR EQUALITY
+        #RGB converting pagesizes to ints means we are accurate to one point
+        #RGB I suggest we should be aiming a little better
+        cp = None
+        dp = None
+        sp = None
+        if canv._pagesize: cp = map(int, canv._pagesize)
+        if self.pagesize: sp = map(int, self.pagesize)
+        if doc.pagesize: dp = map(int, doc.pagesize)
+        if cp!=sp:
+            if sp:
+                canv.setPageSize(self.pagesize)
+            elif cp!=dp:
+                canv.setPageSize(doc.pagesize)
 
-	def afterDrawPage(self, canv, doc):
-		"""This is called after the last flowable for the page has
-		been processed.  You might use this if the page header or
-		footer needed knowledge of what flowables were drawn on
-		this page."""
-		pass
+    def afterDrawPage(self, canv, doc):
+        """This is called after the last flowable for the page has
+        been processed.  You might use this if the page header or
+        footer needed knowledge of what flowables were drawn on
+        this page."""
+        pass
 
 
 class BaseDocTemplate:
-	"""
-	First attempt at defining a document template class.
+    """
+    First attempt at defining a document template class.
 
-	The basic idea is simple.
-	0)	The document has a list of data associated with it
-		this data should derive from flowables. We'll have
-		special classes like PageBreak, FrameBreak to do things
-		like forcing a page end etc.
+    The basic idea is simple.
+    0)  The document has a list of data associated with it
+        this data should derive from flowables. We'll have
+        special classes like PageBreak, FrameBreak to do things
+        like forcing a page end etc.
 
-	1)	The document has one or more page templates.
+    1)  The document has one or more page templates.
 
-	2)	Each page template has one or more frames.
+    2)  Each page template has one or more frames.
 
-	3)	The document class provides base methods for handling the
-		story events and some reasonable methods for getting the
-		story flowables into the frames.
+    3)  The document class provides base methods for handling the
+        story events and some reasonable methods for getting the
+        story flowables into the frames.
 
-	4)	The document instances can override the base handler routines.
+    4)  The document instances can override the base handler routines.
 
-	Most of the methods for this class are not called directly by the user,
-	but in some advanced usages they may need to be overridden via subclassing.
+    Most of the methods for this class are not called directly by the user,
+    but in some advanced usages they may need to be overridden via subclassing.
 
-	EXCEPTION: doctemplate.build(...) must be called for most reasonable uses
-	since it builds a document using the page template.
+    EXCEPTION: doctemplate.build(...) must be called for most reasonable uses
+    since it builds a document using the page template.
 
-	Each document template builds exactly one document into a file specified
-	by the filename argument on initialization.
+    Each document template builds exactly one document into a file specified
+    by the filename argument on initialization.
 
-	Possible keyword arguments for the initialization:
+    Possible keyword arguments for the initialization:
 
-	pageTemplates: A list of templates.  Must be nonempty.	Names
-	  assigned to the templates are used for referring to them so no two used
-	  templates should have the same name.	For example you might want one template
-	  for a title page, one for a section first page, one for a first page of
-	  a chapter and two more for the interior of a chapter on odd and even pages.
-	  If this argument is omitted then at least one pageTemplate should be provided
-	  using the addPageTemplates method before the document is built.
-	showBoundary: if set draw a box around the frame boundaries.
-	leftMargin:
-	rightMargin:
-	topMargin:
-	bottomMargin:  Margin sizes in points (default 1 inch)
-	  These margins may be overridden by the pageTemplates.  They are primarily of interest
-	  for the SimpleDocumentTemplate subclass.
-	allowSplitting:  If set flowables (eg, paragraphs) may be split across frames or pages
-	  (default: 1)
-	title: Internal title for document (does not automatically display on any page)
-	author: Internal author for document (does not automatically display on any page)
-	"""
-	_initArgs = {	'pagesize':defaultPageSize,
-					'pageTemplates':[],
-					'showBoundary':0,
-					'leftMargin':inch,
-					'rightMargin':inch,
-					'topMargin':inch,
-					'bottomMargin':inch,
-					'allowSplitting':1,
-					'title':None,
-					'author':None,
-					'_pageBreakQuick':1}
-	_invalidInitArgs = ()
+    pageTemplates: A list of templates.  Must be nonempty.  Names
+      assigned to the templates are used for referring to them so no two used
+      templates should have the same name.  For example you might want one template
+      for a title page, one for a section first page, one for a first page of
+      a chapter and two more for the interior of a chapter on odd and even pages.
+      If this argument is omitted then at least one pageTemplate should be provided
+      using the addPageTemplates method before the document is built.
+    showBoundary: if set draw a box around the frame boundaries.
+    leftMargin:
+    rightMargin:
+    topMargin:
+    bottomMargin:  Margin sizes in points (default 1 inch)
+      These margins may be overridden by the pageTemplates.  They are primarily of interest
+      for the SimpleDocumentTemplate subclass.
+    allowSplitting:  If set flowables (eg, paragraphs) may be split across frames or pages
+      (default: 1)
+    title: Internal title for document (does not automatically display on any page)
+    author: Internal author for document (does not automatically display on any page)
+    """
+    _initArgs = {   'pagesize':defaultPageSize,
+                    'pageTemplates':[],
+                    'showBoundary':0,
+                    'leftMargin':inch,
+                    'rightMargin':inch,
+                    'topMargin':inch,
+                    'bottomMargin':inch,
+                    'allowSplitting':1,
+                    'title':None,
+                    'author':None,
+                    '_pageBreakQuick':1}
+    _invalidInitArgs = ()
 
-	def __init__(self, filename, **kw):
-		"""create a document template bound to a filename (see class documentation for keyword arguments)"""
-		self.filename = filename
-
-		for k in self._initArgs.keys():
-			if not kw.has_key(k):
-				v = self._initArgs[k]
-			else:
-				if k in self._invalidInitArgs:
-					raise ValueError, "Invalid argument %s" % k
-				v = kw[k]
-			setattr(self,k,v)
-		#print "pagesize is", self.pagesize
+    def __init__(self, filename, **kw):
+        """create a document template bound to a filename (see class documentation for keyword arguments)"""
+        self.filename = filename
 
-		p = self.pageTemplates
-		self.pageTemplates = []
-		self.addPageTemplates(p)
+        for k in self._initArgs.keys():
+            if not kw.has_key(k):
+                v = self._initArgs[k]
+            else:
+                if k in self._invalidInitArgs:
+                    raise ValueError, "Invalid argument %s" % k
+                v = kw[k]
+            setattr(self,k,v)
+        #print "pagesize is", self.pagesize
 
-		# facility to assist multi-build and cross-referencing.
-		# various hooks can put things into here - key is what
-		# you want, value is a page number.  This can then be
-		# passed to indexing flowables.
-		self._pageRefs = {}
-		self._indexingFlowables = []
+        p = self.pageTemplates
+        self.pageTemplates = []
+        self.addPageTemplates(p)
 
-		self._calc()
-		self.afterInit()
-
-	def _calc(self):
-		self._rightMargin = self.pagesize[0] - self.rightMargin
-		self._topMargin = self.pagesize[1] - self.topMargin
-		self.width = self._rightMargin - self.leftMargin
-		self.height = self._topMargin - self.bottomMargin
+        # facility to assist multi-build and cross-referencing.
+        # various hooks can put things into here - key is what
+        # you want, value is a page number.  This can then be
+        # passed to indexing flowables.
+        self._pageRefs = {}
+        self._indexingFlowables = []
 
 
-	def clean_hanging(self):
-		'handle internal postponed actions'
-		while len(self._hanging):
-			self.handle_flowable(self._hanging)
+        #callback facility
+        self._onPage = None
+        self._calc()
+        self.afterInit()
+
+    def _calc(self):
+        self._rightMargin = self.pagesize[0] - self.rightMargin
+        self._topMargin = self.pagesize[1] - self.topMargin
+        self.width = self._rightMargin - self.leftMargin
+        self.height = self._topMargin - self.bottomMargin
+
+    def setPageCallBack(self, func):
+        'Progress monitor - func(pageNo) called on each new page'
+        self._onPage = func
 
-	def addPageTemplates(self,pageTemplates):
-		'add one or a sequence of pageTemplates'
-		if type(pageTemplates) not in (ListType,TupleType):
-			pageTemplates = [pageTemplates]
-		#this test below fails due to inconsistent imports!
-		#assert filter(lambda x: not isinstance(x,PageTemplate), pageTemplates)==[], "pageTemplates argument error"
-		for t in pageTemplates:
-			self.pageTemplates.append(t)
+    def clean_hanging(self):
+        'handle internal postponed actions'
+        while len(self._hanging):
+            self.handle_flowable(self._hanging)
 
-	def handle_documentBegin(self):
-		'''implement actions at beginning of document'''
-		self._hanging = [PageBegin]
-		self.pageTemplate = self.pageTemplates[0]
-		self.page = 0
-		self.beforeDocument()
+    def addPageTemplates(self,pageTemplates):
+        'add one or a sequence of pageTemplates'
+        if type(pageTemplates) not in (ListType,TupleType):
+            pageTemplates = [pageTemplates]
+        #this test below fails due to inconsistent imports!
+        #assert filter(lambda x: not isinstance(x,PageTemplate), pageTemplates)==[], "pageTemplates argument error"
+        for t in pageTemplates:
+            self.pageTemplates.append(t)
+
+    def handle_documentBegin(self):
+        '''implement actions at beginning of document'''
+        self._hanging = [PageBegin]
+        self.pageTemplate = self.pageTemplates[0]
+        self.page = 0
+        self.beforeDocument()
 
-	def handle_pageBegin(self):
-		'''Perform actions required at beginning of page.
-		shouldn't normally be called directly'''
-		self.page = self.page + 1
-		self.pageTemplate.beforeDrawPage(self.canv,self)
-		self.pageTemplate.checkPageSize(self.canv,self)
-		self.pageTemplate.onPage(self.canv,self)
-		for f in self.pageTemplate.frames: f._reset()
-		self.beforePage()
-		if hasattr(self,'_nextFrameIndex'):
-			del self._nextFrameIndex
-		self.frame = self.pageTemplate.frames[0]
-		self.handle_frameBegin()
+    def handle_pageBegin(self):
+        '''Perform actions required at beginning of page.
+        shouldn't normally be called directly'''
+        self.page = self.page + 1
+        self.pageTemplate.beforeDrawPage(self.canv,self)
+        self.pageTemplate.checkPageSize(self.canv,self)
+        self.pageTemplate.onPage(self.canv,self)
+        for f in self.pageTemplate.frames: f._reset()
+        self.beforePage()
+        if hasattr(self,'_nextFrameIndex'):
+            del self._nextFrameIndex
+        self.frame = self.pageTemplate.frames[0]
+        self.handle_frameBegin()
 
-	def handle_pageEnd(self):
-		''' show the current page
-			check the next page template
-			hang a page begin
-		'''
-		self.pageTemplate.afterDrawPage(self.canv, self)
-		self.pageTemplate.onPageEnd(self.canv, self)
-		self.afterPage()
-		self.canv.showPage()
-		if hasattr(self,'_nextPageTemplateIndex'):
-			self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex]
-			del self._nextPageTemplateIndex
-		self._hanging.append(PageBegin)
+    def handle_pageEnd(self):
+        ''' show the current page
+            check the next page template
+            hang a page begin
+        '''
+        self.pageTemplate.afterDrawPage(self.canv, self)
+        self.pageTemplate.onPageEnd(self.canv, self)
+        self.afterPage()
+        self.canv.showPage()
+        if hasattr(self,'_nextPageTemplateIndex'):
+            self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex]
+            del self._nextPageTemplateIndex
+        self._hanging.append(PageBegin)
 
-	def handle_pageBreak(self):
-		'''some might choose not to end all the frames'''
-		if self._pageBreakQuick:
-			self.handle_pageEnd()
-		else:
-			n = len(self._hanging)
-			while len(self._hanging)==n:
-				self.handle_frameEnd()
+    def handle_pageBreak(self):
+        '''some might choose not to end all the frames'''
+        if self._pageBreakQuick:
+            self.handle_pageEnd()
+        else:
+            n = len(self._hanging)
+            while len(self._hanging)==n:
+                self.handle_frameEnd()
 
-	def handle_frameBegin(self,resume=0):
-		'''What to do at the beginning of a frame'''
-		f = self.frame
-		if f._atTop:
-			if self.showBoundary or self.frame.showBoundary:
-				self.frame.drawBoundary(self.canv)
+    def handle_frameBegin(self,resume=0):
+        '''What to do at the beginning of a frame'''
+        f = self.frame
+        if f._atTop:
+            if self.showBoundary or self.frame.showBoundary:
+                self.frame.drawBoundary(self.canv)
 
-	def handle_frameEnd(self,resume=0):
-		''' Handles the semantics of the end of a frame. This includes the selection of
-			the next frame or if this is the last frame then invoke pageEnd.
-		'''
-		if hasattr(self,'_nextFrameIndex'):
-			frame = self.pageTemplate.frames[self._nextFrameIndex]
-			del self._nextFrameIndex
-			self.handle_frameBegin(resume)
-		elif hasattr(self.frame,'lastFrame') or self.frame is self.pageTemplate.frames[-1]:
-			self.handle_pageEnd()
-			self.frame = None
-		else:
-			f = self.frame
-			self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1]
-			self.handle_frameBegin()
+    def handle_frameEnd(self,resume=0):
+        ''' Handles the semantics of the end of a frame. This includes the selection of
+            the next frame or if this is the last frame then invoke pageEnd.
+        '''
+        if hasattr(self,'_nextFrameIndex'):
+            frame = self.pageTemplate.frames[self._nextFrameIndex]
+            del self._nextFrameIndex
+            self.handle_frameBegin(resume)
+        elif hasattr(self.frame,'lastFrame') or self.frame is self.pageTemplate.frames[-1]:
+            self.handle_pageEnd()
+            self.frame = None
+        else:
+            f = self.frame
+            self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1]
+            self.handle_frameBegin()
 
-	def handle_nextPageTemplate(self,pt):
-		'''On endPage chenge to the page template with name or index pt'''
-		if type(pt) is StringType:
-			for t in self.pageTemplates:
-				if t.id == pt:
-					self._nextPageTemplateIndex = self.pageTemplates.index(t)
-					return
-			raise ValueError, "can't find template('%s')"%pt
-		elif type(pt) is IntType:
-			self._nextPageTemplateIndex = pt
-		else:
-			raise TypeError, "argument pt should be string or integer"
+    def handle_nextPageTemplate(self,pt):
+        '''On endPage chenge to the page template with name or index pt'''
+        if type(pt) is StringType:
+            for t in self.pageTemplates:
+                if t.id == pt:
+                    self._nextPageTemplateIndex = self.pageTemplates.index(t)
+                    return
+            raise ValueError, "can't find template('%s')"%pt
+        elif type(pt) is IntType:
+            self._nextPageTemplateIndex = pt
+        else:
+            raise TypeError, "argument pt should be string or integer"
 
-	def handle_nextFrame(self,fx):
-		'''On endFrame chenge to the frame with name or index fx'''
-		if type(fx) is StringType:
-			for f in self.pageTemplate.frames:
-				if f.id == fx:
-					self._nextFrameIndex = self.pageTemplate.frames.index(f)
-					return
-			raise ValueError, "can't find frame('%s')"%fx
-		elif type(fx) is IntType:
-			self._nextFrameIndex = fx
-		else:
-			raise TypeError, "argument fx should be string or integer"
+    def handle_nextFrame(self,fx):
+        '''On endFrame chenge to the frame with name or index fx'''
+        if type(fx) is StringType:
+            for f in self.pageTemplate.frames:
+                if f.id == fx:
+                    self._nextFrameIndex = self.pageTemplate.frames.index(f)
+                    return
+            raise ValueError, "can't find frame('%s')"%fx
+        elif type(fx) is IntType:
+            self._nextFrameIndex = fx
+        else:
+            raise TypeError, "argument fx should be string or integer"
 
-	def handle_currentFrame(self,fx):
-		'''chenge to the frame with name or index fx'''
-		if type(fx) is StringType:
-			for f in self.pageTemplate.frames:
-				if f.id == fx:
-					self._nextFrameIndex = self.pageTemplate.frames.index(f)
-					return
-			raise ValueError, "can't find frame('%s')"%fx
-		elif type(fx) is IntType:
-			self._nextFrameIndex = fx
-		else:
-			raise TypeError, "argument fx should be string or integer"
+    def handle_currentFrame(self,fx):
+        '''chenge to the frame with name or index fx'''
+        if type(fx) is StringType:
+            for f in self.pageTemplate.frames:
+                if f.id == fx:
+                    self._nextFrameIndex = self.pageTemplate.frames.index(f)
+                    return
+            raise ValueError, "can't find frame('%s')"%fx
+        elif type(fx) is IntType:
+            self._nextFrameIndex = fx
+        else:
+            raise TypeError, "argument fx should be string or integer"
 
-	def handle_breakBefore(self, flowables):
-		'''preprocessing step to allow pageBreakBefore and frameBreakBefore attributes'''
-		first = flowables[0]
-		# if we insert a page break before, we'll process that, see it again,
-		# and go in an infinite loop.  So we need to set a flag on the object
-		# saying 'skip me'.  This should be unset on the next pass
-		if hasattr(first, '_skipMeNextTime'):
-			delattr(first, '_skipMeNextTime')
-			return
-		# this could all be made much quicker by putting the attributes
-		# in to the flowables with a defult value of 0
-		if hasattr(first,'pageBreakBefore') and first.pageBreakBefore == 1:
-			first._skipMeNextTime = 1
-			first.insert(0, PageBreak())
-			return
-		if hasattr(first,'style') and hasattr(first.style, 'pageBreakBefore') and first.style.pageBreakBefore == 1:
-			first._skipMeNextTime = 1
-			flowables.insert(0, PageBreak())
-			return
-		if hasattr(first,'frameBreakBefore') and first.frameBreakBefore == 1:
-			first._skipMeNextTime = 1
-			flowables.insert(0, FrameBreak())
-			return
-		if hasattr(first,'style') and hasattr(first.style, 'frameBreakBefore') and first.style.frameBreakBefore == 1:
-			first._skipMeNextTime = 1
-			flowables.insert(0, FrameBreak())
-			return
+    def handle_breakBefore(self, flowables):
+        '''preprocessing step to allow pageBreakBefore and frameBreakBefore attributes'''
+        first = flowables[0]
+        # if we insert a page break before, we'll process that, see it again,
+        # and go in an infinite loop.  So we need to set a flag on the object
+        # saying 'skip me'.  This should be unset on the next pass
+        if hasattr(first, '_skipMeNextTime'):
+            delattr(first, '_skipMeNextTime')
+            return
+        # this could all be made much quicker by putting the attributes
+        # in to the flowables with a defult value of 0
+        if hasattr(first,'pageBreakBefore') and first.pageBreakBefore == 1:
+            first._skipMeNextTime = 1
+            first.insert(0, PageBreak())
+            return
+        if hasattr(first,'style') and hasattr(first.style, 'pageBreakBefore') and first.style.pageBreakBefore == 1:
+            first._skipMeNextTime = 1
+            flowables.insert(0, PageBreak())
+            return
+        if hasattr(first,'frameBreakBefore') and first.frameBreakBefore == 1:
+            first._skipMeNextTime = 1
+            flowables.insert(0, FrameBreak())
+            return
+        if hasattr(first,'style') and hasattr(first.style, 'frameBreakBefore') and first.style.frameBreakBefore == 1:
+            first._skipMeNextTime = 1
+            flowables.insert(0, FrameBreak())
+            return
 
 
-	def handle_keepWithNext(self, flowables):
-		"implements keepWithNext"
-		i = 0
-		n = len(flowables)
-		while i<n and flowables[i].getKeepWithNext(): i = i + 1
-		if i:
-			i = i + 1
-			K = KeepTogether(flowables[:i])
-			for f in K._flowables:
-				f.keepWithNext = 0
-			del flowables[:i]
-			flowables.insert(0,K)
+    def handle_keepWithNext(self, flowables):
+        "implements keepWithNext"
+        i = 0
+        n = len(flowables)
+        while i<n and flowables[i].getKeepWithNext(): i = i + 1
+        if i:
+            i = i + 1
+            K = KeepTogether(flowables[:i])
+            for f in K._flowables:
+                f.keepWithNext = 0
+            del flowables[:i]
+            flowables.insert(0,K)
 
-	def handle_flowable(self,flowables):
-		'''try to handle one flowable from the front of list flowables.'''
+    def handle_flowable(self,flowables):
+        '''try to handle one flowable from the front of list flowables.'''
 
-		#allow document a chance to look at, modify or ignore
-		#the object(s) about to be processed
-		self.filterFlowables(flowables)
+        #allow document a chance to look at, modify or ignore
+        #the object(s) about to be processed
+        self.filterFlowables(flowables)
 
-		self.handle_breakBefore(flowables)
-		self.handle_keepWithNext(flowables)
-		f = flowables[0]
-		del flowables[0]
-		if f is None:
-			return
+        self.handle_breakBefore(flowables)
+        self.handle_keepWithNext(flowables)
+        f = flowables[0]
+        del flowables[0]
+        if f is None:
+            return
 
-		if isinstance(f,PageBreak):
-			self.handle_pageBreak()
-			self.afterFlowable(f)
-		elif isinstance(f,ActionFlowable):
-			f.apply(self)
-			self.afterFlowable(f)
-		else:
-			#try to fit it then draw it
-			if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
-				self.afterFlowable(f)
-			else:
-				#if isinstance(f, KeepTogether): print 'could not add it to frame'
-				if self.allowSplitting:
-					# see if this is a splittable thing
-					S = self.frame.split(f,self.canv)
-					n = len(S)
-				else:
-					n = 0
-				#if isinstance(f, KeepTogether): print 'n=%d' % n
-				if n:
-					if self.frame.add(S[0], self.canv, trySplit=0):
-						self.afterFlowable(S[0])
-					else:
-						print 'n = %d' % n
-						raise "LayoutError", "splitting error on page %d in\n%s" % (self.page,f.identity(30))
-					del S[0]
-					for f in xrange(n-1):
-						flowables.insert(f,S[f])	# put split flowables back on the list
-				else:
-					# this must be cleared when they are finally drawn!
-##					if hasattr(f,'postponed'):
-					if hasattr(f,'_postponed'):
-						message = "Flowable %s too large on page %d" % (f.identity(30), self.page)
-						#show us, it might be handy
-						#HACK = it seems within tables we sometimes
-						#get an empty paragraph that won't fit and this
-						#causes it to fall over.  FIXME FIXME FIXME
-						raise "LayoutError", message
-##					f.postponed = 1
-					f._postponed = 1
-					flowables.insert(0,f)			# put the flowable back
-					self.handle_frameEnd()
+        if isinstance(f,PageBreak):
+            self.handle_pageBreak()
+            self.afterFlowable(f)
+        elif isinstance(f,ActionFlowable):
+            f.apply(self)
+            self.afterFlowable(f)
+        else:
+            #try to fit it then draw it
+            if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
+                self.afterFlowable(f)
+            else:
+                #if isinstance(f, KeepTogether): print 'could not add it to frame'
+                if self.allowSplitting:
+                    # see if this is a splittable thing
+                    S = self.frame.split(f,self.canv)
+                    n = len(S)
+                else:
+                    n = 0
+                #if isinstance(f, KeepTogether): print 'n=%d' % n
+                if n:
+                    if self.frame.add(S[0], self.canv, trySplit=0):
+                        self.afterFlowable(S[0])
+                    else:
+                        print 'n = %d' % n
+                        raise "LayoutError", "splitting error on page %d in\n%s" % (self.page,f.identity(30))
+                    del S[0]
+                    for f in xrange(n-1):
+                        flowables.insert(f,S[f])    # put split flowables back on the list
+                else:
+                    # this must be cleared when they are finally drawn!
+##                  if hasattr(f,'postponed'):
+                    if hasattr(f,'_postponed'):
+                        message = "Flowable %s too large on page %d" % (f.identity(30), self.page)
+                        #show us, it might be handy
+                        #HACK = it seems within tables we sometimes
+                        #get an empty paragraph that won't fit and this
+                        #causes it to fall over.  FIXME FIXME FIXME
+                        raise "LayoutError", message
+##                  f.postponed = 1
+                    f._postponed = 1
+                    flowables.insert(0,f)           # put the flowable back
+                    self.handle_frameEnd()
 
-	#these are provided so that deriving classes can refer to them
-	_handle_documentBegin = handle_documentBegin
-	_handle_pageBegin = handle_pageBegin
-	_handle_pageEnd = handle_pageEnd
-	_handle_frameBegin = handle_frameBegin
-	_handle_frameEnd = handle_frameEnd
-	_handle_flowable = handle_flowable
-	_handle_nextPageTemplate = handle_nextPageTemplate
-	_handle_currentFrame = handle_currentFrame
-	_handle_nextFrame = handle_nextFrame
-
-	def _startBuild(self, filename=None, canvasmaker=canvas.Canvas):
-		self._calc()
-		self.canv = canvasmaker(filename or self.filename,pagesize=self.pagesize)
-		self.handle_documentBegin()
+    #these are provided so that deriving classes can refer to them
+    _handle_documentBegin = handle_documentBegin
+    _handle_pageBegin = handle_pageBegin
+    _handle_pageEnd = handle_pageEnd
+    _handle_frameBegin = handle_frameBegin
+    _handle_frameEnd = handle_frameEnd
+    _handle_flowable = handle_flowable
+    _handle_nextPageTemplate = handle_nextPageTemplate
+    _handle_currentFrame = handle_currentFrame
+    _handle_nextFrame = handle_nextFrame
 
-	def _endBuild(self):
-		if self._hanging!=[] and self._hanging[-1] is PageBegin:
-			del self._hanging[-1]
-			self.clean_hanging()
-		else:
-			self.clean_hanging()
-			self.handle_pageBreak()
+    def _startBuild(self, filename=None, canvasmaker=canvas.Canvas):
+        self._calc()
+        self.canv = canvasmaker(filename or self.filename,pagesize=self.pagesize)
+        if self._onPage:
+            self.canv.setPageCallBack(self._onPage)
+        self.handle_documentBegin()
 
-		self.canv.save()
-		#AR - hack - for some reason a document did not
-		#have these:
-		#if hasattr(self, 'frame'): del self.frame
-		#if hasattr(self, 'pageTemplate'): del self.pageTemplate
-		#del self.frame, self.pageTemplate
+    def _endBuild(self):
+        if self._hanging!=[] and self._hanging[-1] is PageBegin:
+            del self._hanging[-1]
+            self.clean_hanging()
+        else:
+            self.clean_hanging()
+            self.handle_pageBreak()
 
-	def build(self, flowables, filename=None, canvasmaker=canvas.Canvas):
-		"""Build the document from a list of flowables.
-		   If the filename argument is provided then that filename is used
-		   rather than the one provided upon initialization.
-		   If the canvasmaker argument is provided then it will be used
-		   instead of the default.	For example a slideshow might use
-		   an alternate canvas which places 6 slides on a page (by
-		   doing translations, scalings and redefining the page break
-		   operations).
-		"""
-		#assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error"
-		self._startBuild(filename,canvasmaker)
+        self.canv.save()
+        if self._onPage:
+            self.canv.setPageCallBack(None)
+        #AR - hack - for some reason a document did not
+        #have these:
+        #if hasattr(self, 'frame'): del self.frame
+        #if hasattr(self, 'pageTemplate'): del self.pageTemplate
+        #del self.frame, self.pageTemplate
 
-		while len(flowables):
-			self.clean_hanging()
-			self.handle_flowable(flowables)
-
-		self._endBuild()
+    def build(self, flowables, filename=None, canvasmaker=canvas.Canvas):
+        """Build the document from a list of flowables.
+           If the filename argument is provided then that filename is used
+           rather than the one provided upon initialization.
+           If the canvasmaker argument is provided then it will be used
+           instead of the default.  For example a slideshow might use
+           an alternate canvas which places 6 slides on a page (by
+           doing translations, scalings and redefining the page break
+           operations).
+        """
+        #assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error"
+        self._startBuild(filename,canvasmaker)
 
-	def _allSatisfied(self):
-		"""Called by multi-build - are all cross-references resolved?"""
-		allHappy = 1
-		for f in self._indexingFlowables:
-			if not f.isSatisfied():
-				allHappy = 0
-				break
-		return allHappy
+        while len(flowables):
+            self.clean_hanging()
+            self.handle_flowable(flowables)
+
+        self._endBuild()
 
-	def notify(self, kind, stuff):
-		""""Forward to any listeners"""
-		for l in self._indexingFlowables:
-			l.notify(kind, stuff)
-
-	def pageRef(self, label):
-		"""hook to register a page number"""
-		if _verbose: print "pageRef called with label '%s' on page %d" % (
-			label, self.page)
-		self._pageRefs[label] = self.page
+    def _allSatisfied(self):
+        """Called by multi-build - are all cross-references resolved?"""
+        allHappy = 1
+        for f in self._indexingFlowables:
+            if not f.isSatisfied():
+                allHappy = 0
+                break
+        return allHappy
 
-	def multiBuild(self, story,
-				   filename=None,
-				   canvasmaker=canvas.Canvas,
-				   maxPasses = 10):
-		"""Makes multiple passes until all indexing flowables
-		are happy."""
-		self._indexingFlowables = []
-		#scan the story and keep a copy
-		for thing in story:
-			if thing.isIndexing():
-				self._indexingFlowables.append(thing)
-		#print 'scanned story, found these indexing flowables:\n'
-		#print self._indexingFlowables
-		
-		passes = 0
-		while 1:
-			passes = passes + 1
-			if _verbose: print 'building pass '+str(passes) + '...',
+    def notify(self, kind, stuff):
+        """"Forward to any listeners"""
+        for l in self._indexingFlowables:
+            l.notify(kind, stuff)
+
+    def pageRef(self, label):
+        """hook to register a page number"""
+        if _verbose: print "pageRef called with label '%s' on page %d" % (
+            label, self.page)
+        self._pageRefs[label] = self.page
 
-			for fl in self._indexingFlowables:
-				fl.beforeBuild()
+    def multiBuild(self, story,
+                   filename=None,
+                   canvasmaker=canvas.Canvas,
+                   maxPasses = 10):
+        """Makes multiple passes until all indexing flowables
+        are happy."""
+        self._indexingFlowables = []
+        #scan the story and keep a copy
+        for thing in story:
+            if thing.isIndexing():
+                self._indexingFlowables.append(thing)
+        #print 'scanned story, found these indexing flowables:\n'
+        #print self._indexingFlowables
+        
+        passes = 0
+        while 1:
+            passes = passes + 1
+            if _verbose: print 'building pass '+str(passes) + '...',
 
-			# work with a copy of the story, since it is consumed
-			tempStory = story[:]
-			self.build(tempStory, filename, canvasmaker)
-			#self.notify('debug',None)
+            for fl in self._indexingFlowables:
+                fl.beforeBuild()
 
-			#clean up so multi-build does not go wrong - the frame
-			#packer might have tacked an attribute onto some
-			#paragraphs
-			for elem in story:
-##				if hasattr(elem, 'postponed'):
-##					del elem.postponed
-				if hasattr(elem, '_postponed'):
-					del elem._postponed
+            # work with a copy of the story, since it is consumed
+            tempStory = story[:]
+            self.build(tempStory, filename, canvasmaker)
+            #self.notify('debug',None)
 
-			for fl in self._indexingFlowables:
-				fl.afterBuild()
+            #clean up so multi-build does not go wrong - the frame
+            #packer might have tacked an attribute onto some
+            #paragraphs
+            for elem in story:
+##              if hasattr(elem, 'postponed'):
+##                  del elem.postponed
+                if hasattr(elem, '_postponed'):
+                    del elem._postponed
 
-			happy = self._allSatisfied()
+            for fl in self._indexingFlowables:
+                fl.afterBuild()
+
+            happy = self._allSatisfied()
 
-			if happy:
-				## print 'OK'
-				break
-			## else:
-				## print 'failed'
-			if passes > maxPasses:
-				raise IndexError, "Index entries not resolved after %d passes" % maxPasses
+            if happy:
+                ## print 'OK'
+                break
+            ## else:
+                ## print 'failed'
+            if passes > maxPasses:
+                raise IndexError, "Index entries not resolved after %d passes" % maxPasses
 
-		if _verbose: print 'saved'
+        if _verbose: print 'saved'
 
-	#these are pure virtuals override in derived classes
-	#NB these get called at suitable places by the base class
-	#so if you derive and override the handle_xxx methods
-	#it's up to you to ensure that they maintain the needed consistency
-	def afterInit(self):
-		"""This is called after initialisation of the base class."""
-		pass
+    #these are pure virtuals override in derived classes
+    #NB these get called at suitable places by the base class
+    #so if you derive and override the handle_xxx methods
+    #it's up to you to ensure that they maintain the needed consistency
+    def afterInit(self):
+        """This is called after initialisation of the base class."""
+        pass
 
-	def beforeDocument(self):
-		"""This is called before any processing is
-		done on the document."""
-		pass
+    def beforeDocument(self):
+        """This is called before any processing is
+        done on the document."""
+        pass
 
-	def beforePage(self):
-		"""This is called at the beginning of page
-		processing, and immediately before the
-		beforeDrawPage method of the current page
-		template."""
-		pass
+    def beforePage(self):
+        """This is called at the beginning of page
+        processing, and immediately before the
+        beforeDrawPage method of the current page
+        template."""
+        pass
 
-	def afterPage(self):
-		"""This is called after page processing, and
-		immediately after the afterDrawPage method
-		of the current page template."""
-		pass
+    def afterPage(self):
+        """This is called after page processing, and
+        immediately after the afterDrawPage method
+        of the current page template."""
+        pass
 
-	def filterFlowables(self,flowables):
-		'''called to filter flowables at the start of the main handle_flowable method.
-		Upon return if flowables[0] has been set to None it is discarded and the main
-		method returns.
-		'''
-		pass
+    def filterFlowables(self,flowables):
+        '''called to filter flowables at the start of the main handle_flowable method.
+        Upon return if flowables[0] has been set to None it is discarded and the main
+        method returns.
+        '''
+        pass
 
-	def afterFlowable(self, flowable):
-		'''called after a flowable has been rendered'''
-		pass
+    def afterFlowable(self, flowable):
+        '''called after a flowable has been rendered'''
+        pass
 
 
 class SimpleDocTemplate(BaseDocTemplate):
-	"""A special case document template that will handle many simple documents.
-	   See documentation for BaseDocTemplate.  No pageTemplates are required
-	   for this special case.	A page templates are inferred from the
-	   margin information and the onFirstPage, onLaterPages arguments to the build method.
+    """A special case document template that will handle many simple documents.
+       See documentation for BaseDocTemplate.  No pageTemplates are required
+       for this special case.   A page templates are inferred from the
+       margin information and the onFirstPage, onLaterPages arguments to the build method.
 
-	   A document which has all pages with the same look except for the first
-	   page may can be built using this special approach.
-	"""
-	_invalidInitArgs = ('pageTemplates',)
+       A document which has all pages with the same look except for the first
+       page may can be built using this special approach.
+    """
+    _invalidInitArgs = ('pageTemplates',)
 
-	def handle_pageBegin(self):
-		'''override base method to add a change of page template after the firstpage.
-		'''
-		self._handle_pageBegin()
-		self._handle_nextPageTemplate('Later')
+    def handle_pageBegin(self):
+        '''override base method to add a change of page template after the firstpage.
+        '''
+        self._handle_pageBegin()
+        self._handle_nextPageTemplate('Later')
 
-	def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing):
-		"""build the document using the flowables.	Annotate the first page using the onFirstPage
-			   function and later pages using the onLaterPages function.  The onXXX pages should follow
-			   the signature
+    def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing):
+        """build the document using the flowables.  Annotate the first page using the onFirstPage
+               function and later pages using the onLaterPages function.  The onXXX pages should follow
+               the signature
 
-				  def myOnFirstPage(canvas, document):
-					  # do annotations and modify the document
-					  ...
+                  def myOnFirstPage(canvas, document):
+                      # do annotations and modify the document
+                      ...
 
-			   The functions can do things like draw logos, page numbers,
-			   footers, etcetera. They can use external variables to vary
-			   the look (for example providing page numbering or section names).
-		"""
-		self._calc()	#in case we changed margins sizes etc
-		frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal')
-		self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize),
-						PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)])
-		if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
-			self.pageTemplates[0].beforeDrawPage = self.onFirstPage
-		if onLaterPages is _doNothing and hasattr(self,'onLaterPages'):
-			self.pageTemplates[1].beforeDrawPage = self.onLaterPages
-		BaseDocTemplate.build(self,flowables)
+               The functions can do things like draw logos, page numbers,
+               footers, etcetera. They can use external variables to vary
+               the look (for example providing page numbering or section names).
+        """
+        self._calc()    #in case we changed margins sizes etc
+        frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal')
+        self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize),
+                        PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)])
+        if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
+            self.pageTemplates[0].beforeDrawPage = self.onFirstPage
+        if onLaterPages is _doNothing and hasattr(self,'onLaterPages'):
+            self.pageTemplates[1].beforeDrawPage = self.onLaterPages
+        BaseDocTemplate.build(self,flowables)
 
 
-	##########################################################
-	##
-	##	 testing
-	##
-	##########################################################
+    ##########################################################
+    ##
+    ##   testing
+    ##
+    ##########################################################
 
 def randomText():
-	#this may or may not be appropriate in your company
-	from random import randint, choice
+    #this may or may not be appropriate in your company
+    from random import randint, choice
 
-	RANDOMWORDS = ['strategic','direction','proactive',
-	'reengineering','forecast','resources',
-	'forward-thinking','profit','growth','doubletalk',
-	'venture capital','IPO']
+    RANDOMWORDS = ['strategic','direction','proactive',
+    'reengineering','forecast','resources',
+    'forward-thinking','profit','growth','doubletalk',
+    'venture capital','IPO']
 
-	sentences = 5
-	output = ""
-	for sentenceno in range(randint(1,5)):
-		output = output + 'Blah'
-		for wordno in range(randint(10,25)):
-			if randint(0,4)==0:
-				word = choice(RANDOMWORDS)
-			else:
-				word = 'blah'
-			output = output + ' ' +word
-		output = output+'.'
-	return output
+    sentences = 5
+    output = ""
+    for sentenceno in range(randint(1,5)):
+        output = output + 'Blah'
+        for wordno in range(randint(10,25)):
+            if randint(0,4)==0:
+                word = choice(RANDOMWORDS)
+            else:
+                word = 'blah'
+            output = output + ' ' +word
+        output = output+'.'
+    return output
 
 
 if __name__ == '__main__':
 
-	def myFirstPage(canvas, doc):
-		canvas.saveState()
-		canvas.setStrokeColor(red)
-		canvas.setLineWidth(5)
-		canvas.line(66,72,66,PAGE_HEIGHT-72)
-		canvas.setFont('Times-Bold',24)
-		canvas.drawString(108, PAGE_HEIGHT-108, "TABLE OF CONTENTS DEMO")
-		canvas.setFont('Times-Roman',12)
-		canvas.drawString(4 * inch, 0.75 * inch, "First Page")
-		canvas.restoreState()
+    def myFirstPage(canvas, doc):
+        canvas.saveState()
+        canvas.setStrokeColor(red)
+        canvas.setLineWidth(5)
+        canvas.line(66,72,66,PAGE_HEIGHT-72)
+        canvas.setFont('Times-Bold',24)
+        canvas.drawString(108, PAGE_HEIGHT-108, "TABLE OF CONTENTS DEMO")
+        canvas.setFont('Times-Roman',12)
+        canvas.drawString(4 * inch, 0.75 * inch, "First Page")
+        canvas.restoreState()
 
-	def myLaterPages(canvas, doc):
-		canvas.saveState()
-		canvas.setStrokeColor(red)
-		canvas.setLineWidth(5)
-		canvas.line(66,72,66,PAGE_HEIGHT-72)
-		canvas.setFont('Times-Roman',12)
-		canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
-		canvas.restoreState()
+    def myLaterPages(canvas, doc):
+        canvas.saveState()
+        canvas.setStrokeColor(red)
+        canvas.setLineWidth(5)
+        canvas.line(66,72,66,PAGE_HEIGHT-72)
+        canvas.setFont('Times-Roman',12)
+        canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
+        canvas.restoreState()
 
-	def run():
-		objects_to_draw = []
-		from reportlab.lib.styles import ParagraphStyle
-		#from paragraph import Paragraph
-		from doctemplate import SimpleDocTemplate
+    def run():
+        objects_to_draw = []
+        from reportlab.lib.styles import ParagraphStyle
+        #from paragraph import Paragraph
+        from doctemplate import SimpleDocTemplate
 
-		#need a style
-		normal = ParagraphStyle('normal')
-		normal.firstLineIndent = 18
-		normal.spaceBefore = 6
-		import random
-		for i in range(15):
-			height = 0.5 + (2*random.random())
-			box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
-			objects_to_draw.append(box)
-			para = Paragraph(randomText(), normal)
-			objects_to_draw.append(para)
+        #need a style
+        normal = ParagraphStyle('normal')
+        normal.firstLineIndent = 18
+        normal.spaceBefore = 6
+        import random
+        for i in range(15):
+            height = 0.5 + (2*random.random())
+            box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
+            objects_to_draw.append(box)
+            para = Paragraph(randomText(), normal)
+            objects_to_draw.append(para)
 
-		SimpleDocTemplate('doctemplate.pdf').build(objects_to_draw,
-			onFirstPage=myFirstPage,onLaterPages=myLaterPages)
+        SimpleDocTemplate('doctemplate.pdf').build(objects_to_draw,
+            onFirstPage=myFirstPage,onLaterPages=myLaterPages)
 
-	run()
+    run()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/reportlab/test/test_pdfgen_callback.py	Sun Feb 03 21:25:57 2002 +0000
@@ -0,0 +1,37 @@
+#!/bin/env python
+#copyright ReportLab Inc. 2000
+#see license.txt for license details
+#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/test/test_pdfgen_callback.py?cvsroot=reportlab
+#$Header: /tmp/reportlab/reportlab/test/test_pdfgen_callback.py,v 1.1 2002/02/03 21:25:57 andy_robinson Exp $
+__version__=''' $Id: test_pdfgen_callback.py,v 1.1 2002/02/03 21:25:57 andy_robinson Exp $ '''
+__doc__='checks callbacks work'
+
+from reportlab.test import unittest
+from reportlab.pdfgen.canvas import Canvas
+from reportlab.test.test_pdfgen_general import makeDocument
+
+_PAGE_COUNT = 0
+
+class CallBackTestCase(unittest.TestCase):
+    "checks it gets called"
+        
+    def callMe(self, pageNo):
+        self.pageCount = pageNo
+
+    def test1(self):
+        "Make a PDFgen document with most graphics features"
+
+        self.pageCount = 0
+        makeDocument('test_pdfgen_callback.pdf', pageCallBack=self.callMe)
+        #no point saving it!
+        assert self.pageCount >= 7, 'page count not called!'
+
+
+def makeSuite():
+    suite = unittest.TestSuite()
+    suite.addTest(CallBackTestCase('test1'))
+    return suite
+
+    
+if __name__ == "__main__":
+    unittest.TextTestRunner().run(makeSuite())
--- a/reportlab/test/test_pdfgen_general.py	Sun Feb 03 20:16:22 2002 +0000
+++ b/reportlab/test/test_pdfgen_general.py	Sun Feb 03 21:25:57 2002 +0000
@@ -2,8 +2,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/test/testpdfgen.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/test/test_pdfgen_general.py,v 1.9 2001/11/26 22:59:19 andy_robinson Exp $
-__version__=''' $Id: test_pdfgen_general.py,v 1.9 2001/11/26 22:59:19 andy_robinson Exp $ '''
+#$Header: /tmp/reportlab/reportlab/test/test_pdfgen_general.py,v 1.10 2002/02/03 21:25:57 andy_robinson Exp $
+__version__=''' $Id: test_pdfgen_general.py,v 1.10 2002/02/03 21:25:57 andy_robinson Exp $ '''
 __doc__='testscript for reportlab.pdfgen'
 #tests and documents new low-level canvas
 import string
@@ -182,13 +182,15 @@
     canvas.addLiteral('-36 0 Td')
     canvas.setFont('Times-Roman',10)
     
-
-def makeDocument(filename):
+    
+def makeDocument(filename, pageCallBack=None):
     #the extra arg is a hack added later, so other
     #tests can get hold of the canvas just before it is
     #saved
+
     c = canvas.Canvas(filename)
     c.setPageCompression(0)
+    c.setPageCallBack(pageCallBack)
     framePageForm(c) # define the frame form
     c.showOutline()
     
@@ -712,7 +714,8 @@
     #stop
     #apply(c.setOutlineNames0, tuple(outlinenametree))
     return c
-    
+
+
 def run(filename):
     c = makeDocument(filename)
     c.save()
--- a/reportlab/test/test_platypus_general.py	Sun Feb 03 20:16:22 2002 +0000
+++ b/reportlab/test/test_platypus_general.py	Sun Feb 03 21:25:57 2002 +0000
@@ -1,14 +1,14 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/test/testplatypus.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/test/test_platypus_general.py,v 1.5 2001/10/05 01:00:34 andy_robinson Exp $
-__version__=''' $Id: test_platypus_general.py,v 1.5 2001/10/05 01:00:34 andy_robinson Exp $ '''
+#$Header: /tmp/reportlab/reportlab/test/test_platypus_general.py,v 1.6 2002/02/03 21:25:57 andy_robinson Exp $
+__version__=''' $Id: test_platypus_general.py,v 1.6 2002/02/03 21:25:57 andy_robinson Exp $ '''
 
 #tests and documents Page Layout API
 __doc__="""This is not obvious so here's a brief explanation.  This module is both
-the test script and user guide for layout.	Each page has two frames on it:
+the test script and user guide for layout.  Each page has two frames on it:
 one for commentary, and one for demonstration objects which may be drawn in
-various esoteric ways.	The two functions getCommentary() and getExamples()
+various esoteric ways.  The two functions getCommentary() and getExamples()
 return the 'story' for each.  The run() function gets the stories, then
 builds a special "document model" in which the frames are added to each page
 and drawn into.
@@ -36,439 +36,440 @@
 BASEFONT = ('Times-Roman', 10)
 
 def framePage(canvas,doc):
-	#canvas.drawImage("snkanim.gif", 36, 36)
-	canvas.saveState()
-	canvas.setStrokeColorRGB(1,0,0)
-	canvas.setLineWidth(5)
-	canvas.line(66,72,66,PAGE_HEIGHT-72)
+    #canvas.drawImage("snkanim.gif", 36, 36)
+    canvas.saveState()
+    canvas.setStrokeColorRGB(1,0,0)
+    canvas.setLineWidth(5)
+    canvas.line(66,72,66,PAGE_HEIGHT-72)
 
-	canvas.setFont('Times-Italic',12)
-	canvas.drawRightString(523, PAGE_HEIGHT - 56, "Platypus User Guide and Test Script")
-	
-	canvas.setFont('Times-Roman',12)
-	canvas.drawString(4 * inch, 0.75 * inch,
-						"Page %d" % canvas.getPageNumber())
-	canvas.restoreState()
-	
+    canvas.setFont('Times-Italic',12)
+    canvas.drawRightString(523, PAGE_HEIGHT - 56, "Platypus User Guide and Test Script")
+    
+    canvas.setFont('Times-Roman',12)
+    canvas.drawString(4 * inch, 0.75 * inch,
+                        "Page %d" % canvas.getPageNumber())
+    canvas.restoreState()
+    
 def getParagraphs(textBlock):
-	"""Within the script, it is useful to whack out a page in triple
-	quotes containing separate paragraphs. This breaks one into its
-	constituent paragraphs, using blank lines as the delimiter."""
-	lines = string.split(textBlock, '\n')
-	paras = []
-	currentPara = []
-	for line in lines:
-		if len(string.strip(line)) == 0:
-			#blank, add it
-			if currentPara <> []:
-				paras.append(string.join(currentPara, '\n'))
-				currentPara = []
-		else:
-			currentPara.append(line)
-	#...and the last one
-	if currentPara <> []:
-		paras.append(string.join(currentPara, '\n'))
+    """Within the script, it is useful to whack out a page in triple
+    quotes containing separate paragraphs. This breaks one into its
+    constituent paragraphs, using blank lines as the delimiter."""
+    lines = string.split(textBlock, '\n')
+    paras = []
+    currentPara = []
+    for line in lines:
+        if len(string.strip(line)) == 0:
+            #blank, add it
+            if currentPara <> []:
+                paras.append(string.join(currentPara, '\n'))
+                currentPara = []
+        else:
+            currentPara.append(line)
+    #...and the last one
+    if currentPara <> []:
+        paras.append(string.join(currentPara, '\n'))
 
-	return paras
+    return paras
 
 def getCommentary():
-	"""Returns the story for the commentary - all the paragraphs."""
+    """Returns the story for the commentary - all the paragraphs."""
 
-	styleSheet = getSampleStyleSheet()
-	
-	story = []
-	story.append(Paragraph("""
-		PLATYPUS User Guide and Test Script
-		""", styleSheet['Heading1']))
+    styleSheet = getSampleStyleSheet()
+    
+    story = []
+    story.append(Paragraph("""
+        PLATYPUS User Guide and Test Script
+        """, styleSheet['Heading1']))
 
 
-	spam = """
-	Welcome to PLATYPUS!
+    spam = """
+    Welcome to PLATYPUS!
 
-	Platypus stands for "Page Layout and Typography Using Scripts".  It is a high
-	level page layout library which lets you programmatically create complex
-	documents with a minimum of effort.
+    Platypus stands for "Page Layout and Typography Using Scripts".  It is a high
+    level page layout library which lets you programmatically create complex
+    documents with a minimum of effort.
 
-	This document is both the user guide and the output of the test script.
-	In other words, a script used platypus to create the document you are now
-	reading, and the fact that you are reading it proves that it works.  Or
-	rather, that it worked for this script anyway.	It is a first release!	
+    This document is both the user guide and the output of the test script.
+    In other words, a script used platypus to create the document you are now
+    reading, and the fact that you are reading it proves that it works.  Or
+    rather, that it worked for this script anyway.  It is a first release!  
 
-	Platypus is built 'on top of' PDFgen, the Python library for creating PDF
-	documents.	To learn about PDFgen, read the document testpdfgen.pdf.
+    Platypus is built 'on top of' PDFgen, the Python library for creating PDF
+    documents.  To learn about PDFgen, read the document testpdfgen.pdf.
 
-	"""
+    """
 
-	for text in getParagraphs(spam):
-		story.append(Paragraph(text, styleSheet['BodyText']))
+    for text in getParagraphs(spam):
+        story.append(Paragraph(text, styleSheet['BodyText']))
 
-	story.append(Paragraph("""
-		What concepts does PLATYPUS deal with?
-		""", styleSheet['Heading2']))
-	story.append(Paragraph("""
-		The central concepts in PLATYPUS are Flowable Objects, Frames, Flow
-		Management, Styles and Style Sheets, Paragraphs and Tables.  This is
-		best explained in contrast to PDFgen, the layer underneath PLATYPUS.
-		PDFgen is a graphics library, and has primitive commans to draw lines
-		and strings.  There is nothing in it to manage the flow of text down
-		the page.  PLATYPUS works at the conceptual level fo a desktop publishing
-		package; you can write programs which deal intelligently with graphic
-		objects and fit them onto the page.
-		""", styleSheet['BodyText']))
+    story.append(Paragraph("""
+        What concepts does PLATYPUS deal with?
+        """, styleSheet['Heading2']))
+    story.append(Paragraph("""
+        The central concepts in PLATYPUS are Flowable Objects, Frames, Flow
+        Management, Styles and Style Sheets, Paragraphs and Tables.  This is
+        best explained in contrast to PDFgen, the layer underneath PLATYPUS.
+        PDFgen is a graphics library, and has primitive commans to draw lines
+        and strings.  There is nothing in it to manage the flow of text down
+        the page.  PLATYPUS works at the conceptual level fo a desktop publishing
+        package; you can write programs which deal intelligently with graphic
+        objects and fit them onto the page.
+        """, styleSheet['BodyText']))
 
-	story.append(Paragraph("""
-		How is this document organized?
-		""", styleSheet['Heading2']))
+    story.append(Paragraph("""
+        How is this document organized?
+        """, styleSheet['Heading2']))
 
-	story.append(Paragraph("""
-		Since this is a test script, we'll just note how it is organized.
-		the top of each page contains commentary.  The bottom half contains
-		example drawings and graphic elements to whicht he commentary will
-		relate.  Down below, you can see the outline of a text frame, and
-		various bits and pieces within it.	We'll explain how they work
-		on the next page.
-		""", styleSheet['BodyText']))
+    story.append(Paragraph("""
+        Since this is a test script, we'll just note how it is organized.
+        the top of each page contains commentary.  The bottom half contains
+        example drawings and graphic elements to whicht he commentary will
+        relate.  Down below, you can see the outline of a text frame, and
+        various bits and pieces within it.  We'll explain how they work
+        on the next page.
+        """, styleSheet['BodyText']))
 
-	story.append(FrameBreak())
-	#######################################################################
-	#	  Commentary Page 2
-	#######################################################################
-	
-	story.append(Paragraph("""
-		Flowable Objects
-		""", styleSheet['Heading2']))
-	spam = """
-		The first and most fundamental concept is that of a 'Flowable Object'.
-		In PDFgen, you draw stuff by calling methods of the canvas to set up
-		the colors, fonts and line styles, and draw the graphics primitives.
-		If you set the pen color to blue, everything you draw after will be
-		blue until you change it again.  And you have to handle all of the X-Y
-		coordinates yourself.
+    story.append(FrameBreak())
+    #######################################################################
+    #     Commentary Page 2
+    #######################################################################
+    
+    story.append(Paragraph("""
+        Flowable Objects
+        """, styleSheet['Heading2']))
+    spam = """
+        The first and most fundamental concept is that of a 'Flowable Object'.
+        In PDFgen, you draw stuff by calling methods of the canvas to set up
+        the colors, fonts and line styles, and draw the graphics primitives.
+        If you set the pen color to blue, everything you draw after will be
+        blue until you change it again.  And you have to handle all of the X-Y
+        coordinates yourself.
 
-		A 'Flowable object' is exactly what it says.  It knows how to draw itself
-		on the canvas, and the way it does so is totally independent of what
-		you drew before or after.  Furthermore, it draws itself at the location
-		on the page you specify.
+        A 'Flowable object' is exactly what it says.  It knows how to draw itself
+        on the canvas, and the way it does so is totally independent of what
+        you drew before or after.  Furthermore, it draws itself at the location
+        on the page you specify.
 
-		The most fundamental Flowable Objects in most documents are likely to be
-		paragraphs, tables, diagrams/charts and images - but there is no
-		restriction.  You can write your own easily, and I hope that people
-		will start to contribute them.	PINGO users - we provide a "PINGO flowable" object to let
-		you insert platform-independent graphics into the flow of a document.
+        The most fundamental Flowable Objects in most documents are likely to be
+        paragraphs, tables, diagrams/charts and images - but there is no
+        restriction.  You can write your own easily, and I hope that people
+        will start to contribute them.  PINGO users - we provide a "PINGO flowable" object to let
+        you insert platform-independent graphics into the flow of a document.
 
-		When you write a flowable object, you inherit from Flowable and
-		must implement two methods.  object.wrap(availWidth, availHeight) will be called by other parts of
-		the system, and tells you how much space you have.	You should return
-		how much space you are going to use.  For a fixed-size object, this
-		is trivial, but it is critical - PLATYPUS needs to figure out if things
-		will fit on the page before drawing them.  For other objects such as paragraphs,
-		the height is obviously determined by the available width.
+        When you write a flowable object, you inherit from Flowable and
+        must implement two methods.  object.wrap(availWidth, availHeight) will be called by other parts of
+        the system, and tells you how much space you have.  You should return
+        how much space you are going to use.  For a fixed-size object, this
+        is trivial, but it is critical - PLATYPUS needs to figure out if things
+        will fit on the page before drawing them.  For other objects such as paragraphs,
+        the height is obviously determined by the available width.
 
 
-		The second method is object.draw().  Here, you do whatever you want.
-		The Flowable base class sets things up so that you have an origin of
-		(0,0) for your drawing, and everything will fit nicely if you got the
-		height and width right.  It also saves and restores the graphics state
-		around your calls, so you don;t have to reset all the properties you
-		changed.
+        The second method is object.draw().  Here, you do whatever you want.
+        The Flowable base class sets things up so that you have an origin of
+        (0,0) for your drawing, and everything will fit nicely if you got the
+        height and width right.  It also saves and restores the graphics state
+        around your calls, so you don;t have to reset all the properties you
+        changed.
 
-		Programs which actually draw a Flowable don't
-		call draw() this directly - they call object.drawOn(canvas, x, y).
-		So you can write code in your own coordinate system, and things
-		can be drawn anywhere on the page (possibly even scaled or rotated).
-		"""
-	for text in getParagraphs(spam):
-		story.append(Paragraph(text, styleSheet['BodyText']))
+        Programs which actually draw a Flowable don't
+        call draw() this directly - they call object.drawOn(canvas, x, y).
+        So you can write code in your own coordinate system, and things
+        can be drawn anywhere on the page (possibly even scaled or rotated).
+        """
+    for text in getParagraphs(spam):
+        story.append(Paragraph(text, styleSheet['BodyText']))
 
-	story.append(FrameBreak())
-	#######################################################################
-	#	  Commentary Page 3
-	#######################################################################
+    story.append(FrameBreak())
+    #######################################################################
+    #     Commentary Page 3
+    #######################################################################
 
-	story.append(Paragraph("""
-		Available Flowable Objects
-		""", styleSheet['Heading2']))
+    story.append(Paragraph("""
+        Available Flowable Objects
+        """, styleSheet['Heading2']))
 
-	story.append(Paragraph("""
-		Platypus comes with a basic set of flowable objects.  Here we list their
-		class names and tell you what they do:
-		""", styleSheet['BodyText']))
-	#we can use the bullet feature to do a definition list
-	story.append(Paragraph("""
-		<para color=green bcolor=red bg=pink>This is a contrived object to give an example of a Flowable -
-		just a fixed-size box with an X through it and a centred string.</para>""",
-			styleSheet['Definition'],
-			bulletText='XBox  '  #hack - spot the extra space after
-			))
-		
-	story.append(Paragraph("""
-		This is the basic unit of a document.  Paragraphs can be finely
-		tuned and offer a host of properties through their associated
-		ParagraphStyle.""",
-			styleSheet['Definition'],
-			bulletText='Paragraph  '  #hack - spot the extra space after
-			))
-	
-	story.append(Paragraph("""
-		This is used for printing code and other preformatted text.
-		There is no wrapping, and line breaks are taken where they occur.
-		Many paragraph style properties do not apply.  You may supply
-		an optional 'dedent' parameter to trim a number of characters
-		off the front of each line.""",
-			styleSheet['Definition'],
-			bulletText='Preformatted  '  #hack - spot the extra space after
-			))
-	story.append(Paragraph("""
-		This is a straight wrapper around an external image file.  By default
-		the image will be drawn at a scale of one pixel equals one point, and
-		centred in the frame.  You may supply an optional width and height.""",
-			styleSheet['Definition'],
-			bulletText='Image  '  #hack - spot the extra space after
-			))
-		
-	story.append(Paragraph("""
-		This is a table drawing class; it is intended to be simpler
-		than a full HTML table model yet be able to draw attractive output,
-		and behave intelligently when the numbers of rows and columns vary.
-		Still need to add the cell properties (shading, alignment, font etc.)""",
-			styleSheet['Definition'],
-			bulletText='Table  '  #hack - spot the extra space after
-			))
+    story.append(Paragraph("""
+        Platypus comes with a basic set of flowable objects.  Here we list their
+        class names and tell you what they do:
+        """, styleSheet['BodyText']))
+    #we can use the bullet feature to do a definition list
+    story.append(Paragraph("""
+        <para color=green bcolor=red bg=pink>This is a contrived object to give an example of a Flowable -
+        just a fixed-size box with an X through it and a centred string.</para>""",
+            styleSheet['Definition'],
+            bulletText='XBox  '  #hack - spot the extra space after
+            ))
+        
+    story.append(Paragraph("""
+        This is the basic unit of a document.  Paragraphs can be finely
+        tuned and offer a host of properties through their associated
+        ParagraphStyle.""",
+            styleSheet['Definition'],
+            bulletText='Paragraph  '  #hack - spot the extra space after
+            ))
+    
+    story.append(Paragraph("""
+        This is used for printing code and other preformatted text.
+        There is no wrapping, and line breaks are taken where they occur.
+        Many paragraph style properties do not apply.  You may supply
+        an optional 'dedent' parameter to trim a number of characters
+        off the front of each line.""",
+            styleSheet['Definition'],
+            bulletText='Preformatted  '  #hack - spot the extra space after
+            ))
+    story.append(Paragraph("""
+        This is a straight wrapper around an external image file.  By default
+        the image will be drawn at a scale of one pixel equals one point, and
+        centred in the frame.  You may supply an optional width and height.""",
+            styleSheet['Definition'],
+            bulletText='Image  '  #hack - spot the extra space after
+            ))
+        
+    story.append(Paragraph("""
+        This is a table drawing class; it is intended to be simpler
+        than a full HTML table model yet be able to draw attractive output,
+        and behave intelligently when the numbers of rows and columns vary.
+        Still need to add the cell properties (shading, alignment, font etc.)""",
+            styleSheet['Definition'],
+            bulletText='Table  '  #hack - spot the extra space after
+            ))
 
-	story.append(Paragraph("""
-		This is a 'null object' which merely takes up space on the page.
-		Use it when you want some extra padding betweene elements.""",
-			styleSheet['Definition'],
-			bulletText='Spacer '  #hack - spot the extra space after
-			))
+    story.append(Paragraph("""
+        This is a 'null object' which merely takes up space on the page.
+        Use it when you want some extra padding betweene elements.""",
+            styleSheet['Definition'],
+            bulletText='Spacer '  #hack - spot the extra space after
+            ))
 
-	story.append(Paragraph("""
-		A FrameBreak causes the document to call its handle_frameEnd method.""",
-			styleSheet['Definition'],
-			bulletText='FrameBreak	'  #hack - spot the extra space after
-			))
+    story.append(Paragraph("""
+        A FrameBreak causes the document to call its handle_frameEnd method.""",
+            styleSheet['Definition'],
+            bulletText='FrameBreak  '  #hack - spot the extra space after
+            ))
 
-	story.append(Paragraph("""
-		This is in progress, but a macro is basically a chunk of Python code to
-		be evaluated when it is drawn.	It could do lots of neat things.""",
-			styleSheet['Definition'],
-			bulletText='Macro  '  #hack - spot the extra space after
-			))
+    story.append(Paragraph("""
+        This is in progress, but a macro is basically a chunk of Python code to
+        be evaluated when it is drawn.  It could do lots of neat things.""",
+            styleSheet['Definition'],
+            bulletText='Macro  '  #hack - spot the extra space after
+            ))
 
-	story.append(FrameBreak())
+    story.append(FrameBreak())
 
-	story.append(Paragraph(
-				"The next example uses a custom font",
-				styleSheet['Italic']))
+    story.append(Paragraph(
+                "The next example uses a custom font",
+                styleSheet['Italic']))
 
-	story.append(FrameBreak())
-	return story
+    story.append(FrameBreak())
+    return story
 
 def getExamples():
-	"""Returns all the example flowable objects"""
-	styleSheet = getSampleStyleSheet()
-	
-	story = []
+    """Returns all the example flowable objects"""
+    styleSheet = getSampleStyleSheet()
+    
+    story = []
 
-	#make a style with indents and spacing
-	sty = ParagraphStyle('obvious', None)
-	sty.leftIndent = 18
-	sty.rightIndent = 18
-	sty.firstLineIndent = 18
-	sty.spaceBefore = 6
-	sty.spaceAfter = 6
-	story.append(Paragraph("""Now for some demo stuff - we need some on this page,
-		even before we explain the concepts fully""", styleSheet['BodyText']))
-	p = Paragraph("""
-		Platypus is all about fitting objects into frames on the page.	You
-		are looking at a fairly simple Platypus paragraph in Debug mode.
-		It has some gridlines drawn around it to show the left and right indents,
-		and the space before and after, all of which are attributes set in
-		the style sheet.  To be specific, this paragraph has left and
-		right indents of 18 points, a first line indent of 36 points,
-		and 6 points of space before and after itself.	A paragraph
-		object fills the width of the enclosing frame, as you would expect.""", sty)
+    #make a style with indents and spacing
+    sty = ParagraphStyle('obvious', None)
+    sty.leftIndent = 18
+    sty.rightIndent = 18
+    sty.firstLineIndent = 18
+    sty.spaceBefore = 6
+    sty.spaceAfter = 6
+    story.append(Paragraph("""Now for some demo stuff - we need some on this page,
+        even before we explain the concepts fully""", styleSheet['BodyText']))
+    p = Paragraph("""
+        Platypus is all about fitting objects into frames on the page.  You
+        are looking at a fairly simple Platypus paragraph in Debug mode.
+        It has some gridlines drawn around it to show the left and right indents,
+        and the space before and after, all of which are attributes set in
+        the style sheet.  To be specific, this paragraph has left and
+        right indents of 18 points, a first line indent of 36 points,
+        and 6 points of space before and after itself.  A paragraph
+        object fills the width of the enclosing frame, as you would expect.""", sty)
 
-	p.debug = 1   #show me the borders
-	story.append(p)
+    p.debug = 1   #show me the borders
+    story.append(p)
 
-	story.append(Paragraph("""Same but with justification 1.5 extra leading and green text.""", styleSheet['BodyText']))
-	p = Paragraph("""
-		<para align=justify leading=+1.5 fg=green><font color=red>Platypus</font> is all about fitting objects into frames on the page.  You
-		are looking at a fairly simple Platypus paragraph in Debug mode.
-		It has some gridlines drawn around it to show the left and right indents,
-		and the space before and after, all of which are attributes set in
-		the style sheet.  To be specific, this paragraph has left and
-		right indents of 18 points, a first line indent of 36 points,
-		and 6 points of space before and after itself.	A paragraph
-		object fills the width of the enclosing frame, as you would expect.</para>""", sty)
+    story.append(Paragraph("""Same but with justification 1.5 extra leading and green text.""", styleSheet['BodyText']))
+    p = Paragraph("""
+        <para align=justify leading=+1.5 fg=green><font color=red>Platypus</font> is all about fitting objects into frames on the page.  You
+        are looking at a fairly simple Platypus paragraph in Debug mode.
+        It has some gridlines drawn around it to show the left and right indents,
+        and the space before and after, all of which are attributes set in
+        the style sheet.  To be specific, this paragraph has left and
+        right indents of 18 points, a first line indent of 36 points,
+        and 6 points of space before and after itself.  A paragraph
+        object fills the width of the enclosing frame, as you would expect.</para>""", sty)
 
-	p.debug = 1   #show me the borders
-	story.append(p)
+    p.debug = 1   #show me the borders
+    story.append(p)
 
-	story.append(platypus.XBox(4*inch, 0.75*inch,
-			'This is a box with a fixed size'))
+    story.append(platypus.XBox(4*inch, 0.75*inch,
+            'This is a box with a fixed size'))
 
-	story.append(Paragraph("""
-		All of this is being drawn within a text frame which was defined
-		on the page.  This frame is in 'debug' mode so you can see the border,
-		and also see the margins which it reserves.  A frame does not have
-		to have margins, but they have been set to 6 points each to create
-		a little space around the contents.
-		""", styleSheet['BodyText']))
+    story.append(Paragraph("""
+        All of this is being drawn within a text frame which was defined
+        on the page.  This frame is in 'debug' mode so you can see the border,
+        and also see the margins which it reserves.  A frame does not have
+        to have margins, but they have been set to 6 points each to create
+        a little space around the contents.
+        """, styleSheet['BodyText']))
 
-	story.append(FrameBreak())
+    story.append(FrameBreak())
 
-	#######################################################################
-	#	  Examples Page 2
-	#######################################################################
-	
-	story.append(Paragraph("""
-		Here's the base class for Flowable...
-		""", styleSheet['Italic']))
-	
-	code = '''class Flowable:
-		"""Abstract base class for things to be drawn.	Key concepts:
-	1. It knows its size
-	2. It draws in its own coordinate system (this requires the
-		base API to provide a translate() function.
-		"""
-	def __init__(self):
-		self.width = 0
-		self.height = 0
-		self.wrapped = 0
-		
-	def drawOn(self, canvas, x, y):
-		"Tell it to draw itself on the canvas.	Do not override"
-		self.canv = canvas
-		self.canv.saveState()
-		self.canv.translate(x, y)
+    #######################################################################
+    #     Examples Page 2
+    #######################################################################
+    
+    story.append(Paragraph("""
+        Here's the base class for Flowable...
+        """, styleSheet['Italic']))
+    
+    code = '''class Flowable:
+        """Abstract base class for things to be drawn.  Key concepts:
+    1. It knows its size
+    2. It draws in its own coordinate system (this requires the
+        base API to provide a translate() function.
+        """
+    def __init__(self):
+        self.width = 0
+        self.height = 0
+        self.wrapped = 0
+        
+    def drawOn(self, canvas, x, y):
+        "Tell it to draw itself on the canvas.  Do not override"
+        self.canv = canvas
+        self.canv.saveState()
+        self.canv.translate(x, y)
 
-		self.draw()   #this is the bit you overload
+        self.draw()   #this is the bit you overload
 
-		self.canv.restoreState()
-		del self.canv
-		
-	def wrap(self, availWidth, availHeight):
-		"""This will be called by the enclosing frame before objects
-		are asked their size, drawn or whatever.  It returns the
-		size actually used."""
-		return (self.width, self.height)
-	'''
-	
-	story.append(platypus.Preformatted(code, styleSheet['Code'], dedent=4))
-	story.append(FrameBreak())
-	#######################################################################
-	#	  Examples Page 3
-	#######################################################################
+        self.canv.restoreState()
+        del self.canv
+        
+    def wrap(self, availWidth, availHeight):
+        """This will be called by the enclosing frame before objects
+        are asked their size, drawn or whatever.  It returns the
+        size actually used."""
+        return (self.width, self.height)
+    '''
+    
+    story.append(platypus.Preformatted(code, styleSheet['Code'], dedent=4))
+    story.append(FrameBreak())
+    #######################################################################
+    #     Examples Page 3
+    #######################################################################
 
-	story.append(Paragraph(
-				"Here are some examples of the remaining objects above.",
-				styleSheet['Italic']))
-	
-	story.append(Paragraph("This is a bullet point", styleSheet['Bullet'], bulletText='O'))
-	story.append(Paragraph("Another bullet point", styleSheet['Bullet'], bulletText='O'))
-	
-	story.append(Paragraph(
-				"Here is an Image.	For now, these are always centred in the frame.",
-				styleSheet['Italic']))
+    story.append(Paragraph(
+                "Here are some examples of the remaining objects above.",
+                styleSheet['Italic']))
+    
+    story.append(Paragraph("This is a bullet point", styleSheet['Bullet'], bulletText='O'))
+    story.append(Paragraph("Another bullet point", styleSheet['Bullet'], bulletText='O'))
+    
+    story.append(Paragraph(
+                "Here is an Image.  For now, these are always centred in the frame.",
+                styleSheet['Italic']))
 
-	img = platypus.Image('pythonpowered.gif')
-	story.append(img)
+    img = platypus.Image('pythonpowered.gif')
+    story.append(img)
 
-	story.append(Paragraph("""Here is a Table, which takes all kinds of formatting options...""",
-				styleSheet['Italic']))
-	story.append(platypus.Spacer(0, 12))
-	
-	g = platypus.Table(
-			(('','North','South','East','West'),
-			 ('Quarter 1',100,200,300,400),
-			 ('Quarter 2',100,200,300,400),
-			 ('Total',200,400,600,800)),
-			(72,36,36,36,36),
-			(24, 16,16,18)
-			)
-	style = platypus.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'),
-							   ('ALIGN', (0,0), (-1,0), 'CENTRE'),
-							   ('GRID', (0,0), (-1,-1), 0.25, colors.black),
-							   ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
-							   ('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)),
-							   ('TEXTCOLOR', (0,1), (0,-1), colors.black),
-							   ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))
-							   ])
-	g.setStyle(style)
-	story.append(g)
-	story.append(FrameBreak())
-	
-	#######################################################################
-	#	  Examples Page 4 - custom fonts
-	#######################################################################
+    story.append(Paragraph("""Here is a Table, which takes all kinds of formatting options...""",
+                styleSheet['Italic']))
+    story.append(platypus.Spacer(0, 12))
+    
+    g = platypus.Table(
+            (('','North','South','East','West'),
+             ('Quarter 1',100,200,300,400),
+             ('Quarter 2',100,200,300,400),
+             ('Total',200,400,600,800)),
+            (72,36,36,36,36),
+            (24, 16,16,18)
+            )
+    style = platypus.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'),
+                               ('ALIGN', (0,0), (-1,0), 'CENTRE'),
+                               ('GRID', (0,0), (-1,-1), 0.25, colors.black),
+                               ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
+                               ('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)),
+                               ('TEXTCOLOR', (0,1), (0,-1), colors.black),
+                               ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))
+                               ])
+    g.setStyle(style)
+    story.append(g)
+    story.append(FrameBreak())
+    
+    #######################################################################
+    #     Examples Page 4 - custom fonts
+    #######################################################################
 
 
-	# custom font with LettError-Robot font
-	import reportlab.rl_config
-	reportlab.rl_config.warnOnMissingFontGlyphs = 0
-	
-	from reportlab.pdfbase import pdfmetrics
-	face = pdfmetrics.EmbeddedType1Face('../fonts/LeERC___.AFM','../fonts/LeERC___.PFB')
-	faceName = face.name  # should be 'LettErrorRobot-Chrome'
-	pdfmetrics.registerTypeFace(face)
-	font = pdfmetrics.Font(faceName, faceName, 'WinAnsiEncoding')		
-	pdfmetrics.registerFont(font)
+    # custom font with LettError-Robot font
+    import reportlab.rl_config
+    reportlab.rl_config.warnOnMissingFontGlyphs = 0
+    
+    from reportlab.pdfbase import pdfmetrics
+    face = pdfmetrics.EmbeddedType1Face('../fonts/LeERC___.AFM','../fonts/LeERC___.PFB')
+    faceName = face.name  # should be 'LettErrorRobot-Chrome'
+    pdfmetrics.registerTypeFace(face)
+    font = pdfmetrics.Font(faceName, faceName, 'WinAnsiEncoding')       
+    pdfmetrics.registerFont(font)
 
 
-	# put it inside a paragraph.
-	story.append(Paragraph(
-		"""This is an ordinary paragraph, which happens to contain
-		text in an embedded font:
-		<font name="LettErrorRobot-Chrome">LettErrorRobot-Chrome</font>.
-		Now for the real challenge...""", styleSheet['Normal']))
+    # put it inside a paragraph.
+    story.append(Paragraph(
+        """This is an ordinary paragraph, which happens to contain
+        text in an embedded font:
+        <font name="LettErrorRobot-Chrome">LettErrorRobot-Chrome</font>.
+        Now for the real challenge...""", styleSheet['Normal']))
 
 
-	styRobot = ParagraphStyle('Robot', styleSheet['Normal'])
-	styRobot.fontSize = 16
-	styRobot.leading = 20
-	styRobot.fontName = 'LettErrorRobot-Chrome'
-	
-	story.append(Paragraph(
-				"This whole paragraph is 16-point Letterror-Robot-Chrome.",
-				styRobot))
-	story.append(FrameBreak())
-	
+    styRobot = ParagraphStyle('Robot', styleSheet['Normal'])
+    styRobot.fontSize = 16
+    styRobot.leading = 20
+    styRobot.fontName = 'LettErrorRobot-Chrome'
+    
+    story.append(Paragraph(
+                "This whole paragraph is 16-point Letterror-Robot-Chrome.",
+                styRobot))
+    story.append(FrameBreak())
+    
 
-	return story
+    return story
 
 class AndyTemplate(BaseDocTemplate):
-	_invalidInitArgs = ('pageTemplates',)
-	def __init__(self, filename, **kw):
-		frame1 = platypus.Frame(inch, 5.6*inch, 6*inch, 5.2*inch,id='F1')
-		frame2 = platypus.Frame(inch, inch, 6*inch, 4.5*inch, showBoundary=1,id='F2')
-		self.allowSplitting = 0
-		apply(BaseDocTemplate.__init__,(self,filename),kw)
-		self.addPageTemplates(PageTemplate('normal',[frame1,frame2],framePage))
+    _invalidInitArgs = ('pageTemplates',)
+    def __init__(self, filename, **kw):
+        frame1 = platypus.Frame(inch, 5.6*inch, 6*inch, 5.2*inch,id='F1')
+        frame2 = platypus.Frame(inch, inch, 6*inch, 4.5*inch, showBoundary=1,id='F2')
+        self.allowSplitting = 0
+        apply(BaseDocTemplate.__init__,(self,filename),kw)
+        self.addPageTemplates(PageTemplate('normal',[frame1,frame2],framePage))
 
-	def	fillFrame(self,flowables):
-		f = self.frame
-		while len(flowables)>0 and f is self.frame:
-			self.handle_flowable(flowables)
+    def fillFrame(self,flowables):
+        f = self.frame
+        while len(flowables)>0 and f is self.frame:
+            self.handle_flowable(flowables)
 
-	def build(self, flowables1, flowables2):
-		assert filter(lambda x: not isinstance(x,Flowable), flowables1)==[], "flowables1 argument error"
-		assert filter(lambda x: not isinstance(x,Flowable), flowables2)==[], "flowables2 argument error"
-		self._startBuild()
-		while (len(flowables1) > 0 or len(flowables1) > 0):
-			self.clean_hanging()
-			self.fillFrame(flowables1)
-			self.fillFrame(flowables2)
+    def build(self, flowables1, flowables2):
+        assert filter(lambda x: not isinstance(x,Flowable), flowables1)==[], "flowables1 argument error"
+        assert filter(lambda x: not isinstance(x,Flowable), flowables2)==[], "flowables2 argument error"
+        self._startBuild()
+        while (len(flowables1) > 0 or len(flowables1) > 0):
+            self.clean_hanging()
+            self.fillFrame(flowables1)
+            self.fillFrame(flowables2)
 
-		self._endBuild()
-
+        self._endBuild()
+def showProgress(pageNo):
+    print 'CALLBACK SAYS: page %d' % pageNo
 def run():
-	doc = AndyTemplate('test_platypus_general.pdf')
-
-	commentary = getCommentary()
-	examples = getExamples()
-	doc.build(commentary,examples)
+    doc = AndyTemplate('test_platypus_general.pdf')
+    #doc.setPageCallBack(showProgress)
+    commentary = getCommentary()
+    examples = getExamples()
+    doc.build(commentary,examples)
 
 class PlatypusTestCase(unittest.TestCase):
     "Make documents with lots of Platypus features"