[reportlab-users] Dual pass numbered canvas causes images to disappear

Chris Kratz chris.kratz at vistashare.com
Wed Nov 12 09:09:06 EST 2008

Hello all,

When generating a pdf, if I use the normal canvas, my image shows up just
fine in the generated pdf.
doc.build(story, onFirstPage=self.firstPage, onLaterPages=self.laterPages)

But, I need the ability to print page x of y in the footers. So, I used a
slightly modified version of the NumberedCanvas class found here:

So, when I call doc.build with the NumberedCanvas, I get the Page x of y in
the footer, but images just seem to not show. No errors or any other
indications of problems, just no images. The document size seems to
indicate the image is included in the pdf, even if it isn't displaying.

doc.build(story, onFirstPage=self.firstPage,
onLaterPages=self.laterPages, canvasmaker=NumberedCanvas)

class NumberedCanvas(canvas.Canvas):

def __init__(self, *args, **kwargs):
canvas.Canvas.__init__(self, *args, **kwargs)
self._codes = []

def showPage(self):
self._codes.append({'code': self._code, 'stack': self._codeStack})

def save(self):
"""add page info to each page (page x of y)"""
# reset page counter
self._pageNumber = 0
for code in self._codes:
# recall saved page
self._code = code['code']
self._codeStack = code['stack']
# handle any headers like page numbers that need to updated
after complete rendering
for x,y,hdrStr,func in self.liveHdrs:
func(x,y,LIVE_HDR_KEYS[hdrStr] % { 'pageNumber' :
'pageTotal' :


* the call to func is a handle to either drawString, drawCentredString or
drawRightString depending on where the user asked for the footer to be

Anyone have any ideas why NumberedCanvas might stop images from showing? Is
there anything I can do to debug this further or a better way to do "Page x
of y"?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20081112/422fce01/attachment.html>

More information about the reportlab-users mailing list