[reportlab-users] newbie help

Robin Becker robin at reportlab.com
Fri Dec 7 06:06:44 EST 2007


Anil wrote:

> Okay, I think I know a little bit more about how Platypus works now.

> So, here is what I guess I am trying to do.

>

> I got a DocTemplate with 2 columns. The question is, how do I draw

> non-flowable shapes on these pages? (Thats why I guess I was wondering

> how to access the canvas from the generate() method from the code I've

> emailed).

>

> I guess the best thing to do is, just use pdfgen and Canvas. Right?


Anil, the doctemplate mechanism provides callables for decorating pages. When
you set up the PageTemplate(s) you can give it onPage and onPageEnd callables
which will be called at the start and end of each page controlled by the
template. They are called as

func(canvas,doctemplate)

so you can pull information from your document and do things to the canvas.


If you want to access the canvas inside a flowable's draw method just use
self.canv. The problem for flowables is that they're not supposed to have access
to the global context. If you want finer control you can try overriding the
flowables drawOn method this has signature

def drawOn(self, canvas, x, y, _sW=0):
--
Robin Becker


More information about the reportlab-users mailing list