Can anyone show an example how to show "page X from Y" on Reportlab's generated document if there is more than one page in a document (show nothing if there is only one page). I know some solutions, but they all mark pages regardless of total page number.
Actually it was pretty easy. Asif's answer on SO How to add total page count in PDF using reportlab helped me. The only thing that was needed was added 'if' clause in the save() function. Original code is here: http://code.activestate.com/recipes/576832/
Tweeked save() function is:
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)
### just a little tweek here
if num_pages > 1:
self.draw_page_number(num_pages)
canvas.Canvas.showPage(self)
canvas.Canvas.save(self)