[reportlab-users] Page 1 of 3
Robin Becker
robin at reportlab.com
Mon Jan 29 07:28:55 EST 2007
Robin Becker wrote:
> Juha Tuomala wrote:
>>
>> On Friday 26 January 2007 19:55, Robin Becker wrote:
>>> The onPageEnd stuff allows you to use canvas level primitives to decorate the
>>> page. Assume you have a form called pageTotal then your page decorator does
>>> something like
>>>
>>> canvas.doForm('pageTotal')
>>>
>>> at the appropriate place on the page. Note that the form need not be defined
>>> when you reference it.
>>>
>>> At the end of the document build you need to set up the form using more canvas
>>> level operations.
>>>
>>> canvas.beginForm('pageTotal')
>>> canvas.saveState()
>>>
>>> ......
>>> canvas.drawString(x,y,str(nPages))
>>> canvas.restoreState()
>>> canvas.endForm()
>>
>> I've not been playing with forms yet, so is this
>> also possible with platypus+flowables?
>>
>> I've laid out my pages with build parameters onFirstPage
>> and onLaterPages.
>>
>>
>> Tuju
>>
>
> Yes you can reference the form in those functions. The hard part is knowing
> which is the 'last' page so you can define the form. A trick will allow you to
> do that though. Add an afterPage method to your document class that knows when
> the story is done.
>
>
> Suppose your class is currently called DocA then either add an afterPage to it
> directly or derive another class from it and add the after page to that class.
>
> class DocB(DocA):
> def afterPage(self):
> if hasattr(self,'_theEndAtLast'):
> #the last flowable has been drawn
> self.canv.beginForm('pageTotal')
whoops should have been
canvas = self.canv
canvas.beginForm('pageTotal')
> canvas.beginForm('pageTotal')
> canvas.saveState()
> canvas.drawString(x,y,str(self.page))
> canvas.restoreState()
> canvas.endForm()
> DocA.afterPage(self) #call the super method
>
>
> The trick is to add a special flowable to your story that sets the attribute
> '_theEndAtLast' onto the document eg
>
> class ThisIsTheEnd(ActionFlowable):
> def apply(self,doc):
> doc._theEndAtLast = 1
>
> right at the end of your story creation
>
> story.append(ThisIsTheEnd())
>
>
> then when that flowable is processed the story is done and the doctemplate
> framework will eventually call afterPage so the form gets defined.
--
Robin Becker
More information about the reportlab-users
mailing list