[reportlab-users] Dynamic information in headers/footers
Andy Robinson
andy at reportlab.com
Wed Feb 9 19:05:50 EST 2005
> Hi,
>
> I was wondering how I can include dynamic information in the
> headers or footers.
>
> I would like to include a person's name in the Header / Footer as long
> as the page is displaying information pertaining to this person. From
> what I have read, you need to supply the page templates prior to
> building the document. This seems to be understandable and I thought
> I would include a variable which contains the people's names in the
> Header in a drawString command. The issue occurs when I'm using
> flowables. I am sending an explicit PageBreak() at which point I'm
> done printing info for the current person and I'm about to start
> printing info for the next person. I do not know how to change the
> value of the variable in this situation and therefore the first
> person's name is displayed on all pages.
>
> How can I resolve this issue?
In general you will need to override the various methods of
the DocTemplate in a subclass, and store a little state in
your derived one. If you override afterFlowable or beforeFlowable,
you get to peek at each thing in the story as it is processed,
and perhaps set some 'person' attribute on the document
which could be displayed by the page template drawing routines.
There is a similar example in reportlab/tools/docco/rltemplate.py
which is used for our user guide. The DocTemplate detects
heading1 styles and infers that a new chapter is starting,
and the page template draws the chapter name on each page.
Sorry this is so terse, we have a lot of staff on vacation
this week (me too if I can finish up tonight!) - if this
doesn't get you there, ask again and hopefully a colleague
will be able to help.
Andy Robinson
More information about the reportlab-users
mailing list