I had been using the reportlab NumberedCanvas given at http://code.activestate.com/recipes/546511/ . However, when i try to build a PDF that contains Image flowables, the images do not show, although enough vertical space is left for the image to fit. Is there any solution for this?
+4
A:
See my new, improved recipe for this, which includes a simple test with images. Here's an excerpt from the recipe (which omits the test code):
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
class NumberedCanvas(canvas.Canvas):
def __init__(self, *args, **kwargs):
canvas.Canvas.__init__(self, *args, **kwargs)
self._saved_page_states = []
def showPage(self):
self._saved_page_states.append(dict(self.__dict__))
self._startPage()
def save(self):
"""add page info to each page (page x of y)"""
num_pages = len(self._saved_page_states)
for state in self._saved_page_states:
self.__dict__.update(state)
self.draw_page_number(num_pages)
canvas.Canvas.showPage(self)
canvas.Canvas.save(self)
def draw_page_number(self, page_count):
self.setFont("Helvetica", 7)
self.drawRightString(200*mm, 20*mm,
"Page %d of %d" % (self._pageNumber, page_count))
Vinay Sajip
2009-07-06 16:51:06
Thanks a lot! This seems to work
2009-07-06 17:12:28
Feel free to upvote ;-)
Vinay Sajip
2009-07-06 17:15:23