[reportlab-users] Example, please: putting TOC at the beginning
Bill Bell
reportlab-users@reportlab.com
Mon, 10 Jun 2002 11:20:16 -0400
My code is very simple, and appears below. Would someone please tell me how=
to move the table of contents to the beginning of the document from the=
end.
Thanks!
Bill
------------------------
class SimpleDocTemplateDer ( SimpleDocTemplate ):
def multiBuild(self,flowables,onFirstPage=3D_doNothing,=
onLaterPages=3D_doNothing):
self._calc() #in case we changed margins sizes etc
frameT =3D Frame(self.leftMargin, self.bottomMargin, self.width,=
self.height, id=3D'normal')
self.addPageTemplates([PageTemplate(id=3D'First',frames=3DframeT,=
onPage=3DonFirstPage,pagesize=3Dself.pagesize),
PageTemplate(id=3D'Later',frames=3DframeT,=
onPage=3DonLaterPages,pagesize=3Dself.pagesize)])
if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
self.pageTemplates[0].beforeDrawPage =3D self.onFirstPage
if onLaterPages is _doNothing and hasattr(self,'onLaterPages'):
self.pageTemplates[1].beforeDrawPage =3D self.onLaterPages
BaseDocTemplate.multiBuild(self,flowables)
def afterFlowable ( self, flowable ):
if hasattr(flowable, 'style'):
if flowable . style . name =3D=3D 'Section':
pageTabs [ self . page ] =3D flowable . getPlainText ( )
self . notify ( 'TOCEntry', ( 0, flowable . getPlainText (=
), self . page ) )
def go():
toc =3D TableOfContents ( )
Elements . append ( toc )
doc =3D SimpleDocTemplateDer ( 'PDFcomplete.pdf',
leftMargin =3D 0.5 * inch, rightMargin =3D 0.5 * inch, topMargin=
=3D 1 * inch, bottomMargin =3D 0.75 * inch )
doc . multiBuild ( Elements, onFirstPage =3D newPage, onLaterPages =3D=
newPage )
------------
"It is the time that you have wasted for your rose that makes your rose so=
important."--St-Exupery