[reportlab-users] Example, please: putting TOC at the beginning

Aaron Watters reportlab-users@reportlab.com
Tue, 11 Jun 2002 12:53:41 -0400


Well, if you know how many pages are in the toc you can put the toc into 
one or more forms
-- "draw" the forms at the beginning of the process and then "define" 
them at the end (forms
are lazy and may be defined after they have been referenced).  Just to 
be confusing I'm talking about
"PDF xform objects" defined in reportlab using canvas.beginForm ... 
canvas.endForm, not
"Adobe forms" which are not yet supported in reportlab... not just 
yet... ;).

    -- Aaron Watters

Bill Bell wrote:

>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=_doNothing, onLaterPages=_doNothing):
>        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.multiBuild(self,flowables)
>
>    def afterFlowable ( self, flowable ):
>        if hasattr(flowable, 'style'):
>            if flowable . style . name == 'Section':
>                pageTabs [ self . page ] = flowable . getPlainText ( )
>                self . notify ( 'TOCEntry', ( 0, flowable . getPlainText ( ), self . page ) )
>
>def go():
>    toc = TableOfContents ( )
>    Elements . append ( toc )
>    doc = SimpleDocTemplateDer ( 'PDFcomplete.pdf',
>        leftMargin = 0.5 * inch, rightMargin = 0.5 * inch, topMargin = 1 * inch, bottomMargin = 0.75 * inch )
>    doc . multiBuild ( Elements, onFirstPage = newPage, onLaterPages = newPage )
>
>
>
>------------
>"It is the time that you have wasted for your rose that makes your rose so important."--St-Exupery
>
>
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users
>
>