[reportlab-users] Page background image with Platypus?

Andy Robinson andy at reportlab.com
Mon Oct 8 18:28:03 EDT 2007


On 08/10/2007, Erik Wickstrom <erik at erikwickstrom.com> wrote:

> I've try fiddling with the size parameters. The largest I can get is with

> about a 2 inch border around the image of blank page. My text is also not

> "layering" on top of the background image, it's being pushed onto the next

> page instead.

>

> The actual dimensions of the image are 8.5x11 inches, so it should fit

> perfectly.

>


Erik, sorry I missed this thread. The discussion so far assumes you
want a huge image as part of the story, but I think you want it as a
background, like a watermark?

Your best bet is to treat your background image as part of a
PageTemplate, overriding the beforeDrawPage method.

If you've been using SimpleDocTemplate so far, you may have missed
this because it creates page templates for you. It's best to directly
use BaseDocTemplate and set it up with your own PageTemplates.
There's some code in reportlab\tools\docco\rltemplate.py showing how
we create a realistic document template with some custom page
templates that 'do stuff' when drawn. These ones user afterDrawPage
to add a company address, but you are going to just call something
like this...

class EriksPageTemplate(PageTemplate):
...snip...
def beforeDrawPage(self, canv):
self.canv.drawImage("watermark.jpg", 0, 0, 8.5*in, 11*in)

This is also the right way to do headers, footers and any other
decoration of pages.

If it only appears on some pages, you can have several page templates,
and put in action flowables to switch to your template in the story
before you need it.

I hope this points you the right way.


Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.


More information about the reportlab-users mailing list