[reportlab-users] Where is my canvas ? :)

John Pywtorak jpywtora at calpoly.edu
Mon Aug 1 20:24:23 EDT 2005


Nicholas Wieland wrote:
> from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, Paragraph
> from reportlab.rl_config import defaultPageSize
> from reportlab.graphics.shapes import Rect
> from reportlab.lib.colors import green
> 
> page_width = defaultPageSize [0]
> page_height = defaultPageSize [1]
> hf = Frame (0, page_height - 200, page_width, 200)
> ff = Frame (0, 0, page_width, page_height - 200)
> r = Rect (0, page_height - 200, page_width, 200, fillColor = green)
> r.fillColor = green
> hf.addFromList ([r])
> pt = PageTemplate (frames = [hf, ff])
> doc = BaseDocTemplate (filename = "foo.pdf", PageTemplates = [pt])
> doc.build ()
>  
>  
> Obviously this doesn't work since I don't pass the canvas as an argument to frame.addFromList.
> I know where to find canvas and how to use it, I'm just experimenting with Platypus, so I'd like to use everything at a high level, to simplify things a bit.
> My question is: do I have to instantiate a canvas to make my script work ? From what I understood (nothing, maybe :p) the BaseDocTemplate class should pass a canvas to PageTemplate and so on.
>  
> TIA,
>   ngw
> 

This may not be exactly an answer, but with Platypus and the
BaseDocTemplate, or SimpleDocTemplate you can define page handlers, like
OnPage which get passed the canvas.  You can do whatever you want with
it there.

-- 
Windows
Start Here
Frustrating Hanging Crashing
Blue Screen of Death
Reboot



More information about the reportlab-users mailing list