[reportlab-users] Embedding Platypus Story in Canvas
Tim Roberts
timr at probo.com
Mon Nov 5 14:47:13 EST 2007
Rich Shepard wrote:
> I've written the report cover page as a platypus story, but have the
> rest
> of the report writing directly to the canvas. I'd like this to be a
> single
> pdf file, with page numbers beginning immediately after the cover page.
>
> The function begins with
>
> Title = self.rptinfo
> pg = canvas.Canvas(Title, pagesize=LETTER)
>
> and I proceed to define a platypus story and table. This ends with
>
> doc.build(story)
>
> but that prints the document, if I correctly understand the dynamics.
Well, ReportLab doesn't actually print anything. By default, the
"build" method calls Canvas.save() to generate the PDF, but you can
override that by setting doc._doSave = 0. Then you can do
doc.canv.showPage() and start drawing more stuff. You could even derive
your own class from SimpleDocTemplate, and override afterInit or
beforeDocument to set that.
> While I'm at it, am I correct that I can print the pagination by
>
> pgnum = pg.getPageNumber()
> pg.drawCentredString(306,36,pgnum)
> pg.showPage()
That should work. I usually store the page size in a global somewhere,
and then do
pg.drawCentredString( PageSize[0] / 2, 36, pgnum )
so I can switch to landscape, for example, without great pain.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list