[reportlab-users] newbie questions
Robin Becker
reportlab-users@reportlab.com
Fri, 11 Jun 2004 20:01:47 +0100
Randall Smith wrote:
> I have a few newbie questions.
>
> 1. When using document and page templates, what's the best way to
> include header/footer information?
>
Header and footer stuff is best done by providing each template with an
onPage attribute. This gets called like
onPage(canvas,document)
Note that this is not a method of the page template, but an ordinary
function. You can also override the methods template.beforeDrawPage,
template.afterDrawPage which are called with canvas & document as
arguments. In side these methods you can do what you want to the canvas.
Note that these are considered low level so you need to wrap stuff in
canvas.save/restore to avoid unwanted side effects.
> 2. I want a flowable to draw a horizontal line that spans the width of
> the page. The draw method is something like this:
>
> def draw(self):
> self.canv.setLineWidth(line_thickness)
> self.canv.line(0, .5 * line_thickness, ?, .5 * line_thickness)
>
> Notice the ?
> How can I know how long to draw the line?
>
Before each flowable is drawn a wrap method
signature wrap(self, availWidth, availHeight)
is called on the flowable. You are supposed to return the amount of
space needed by the flowable. So for your line thing you could use
def wrap(self,availWidth, availHeight):
self._width = availWidth
self._height = line_thickness
return self._width, self._height
then you can refer to the _width attribute when draw gets called.
--
Robin Becker