Index: /main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py	(revision 8112)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py	(revision 8113)
@@ -23,7 +23,8 @@
 from cStringIO import StringIO
 from datetime import datetime
-from reportlab.lib.units import cm, inch
+from reportlab.lib.units import cm, inch, mm
 from reportlab.lib.pagesizes import A4, landscape, portrait
 from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
+from reportlab.pdfgen.canvas import Canvas
 from reportlab.platypus import (
     SimpleDocTemplate, Spacer, Paragraph, Image, Table)
@@ -80,4 +81,53 @@
     html = html.replace('\n', '')
     return html
+
+class NumberedCanvas(Canvas):
+    """A reportlab canvas for numbering pages after all docs are processed.
+
+    Taken from
+    http://code.activestate.com/recipes/546511-page-x-of-y-with-reportlab/
+    http://code.activestate.com/recipes/576832/
+    """
+
+    def __init__(self, *args, **kw):
+        Canvas.__init__(self, *args, **kw)
+        self._saved_page_states = []
+        return
+
+    def showPage(self):
+        self._saved_page_states.append(dict(self.__dict__))
+        self._startPage()
+        return
+
+    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.showPage(self)
+        Canvas.save(self)
+        return
+
+    def draw_page_number(self, page_count):
+        """draw string at bottom right with 'page x of y'.
+
+        Location of the string is determined by canvas attributes
+        `kofa_footer_x_pos` and `kofa_footer_y_pos` that have to be
+        set manually.
+
+        If this canvas also provides an attribute `kofa_footer_text`,
+        the contained text is rendered left of the ``page x of y``
+        string.
+        """
+        self.setFont("Helvetica", 9)
+        right_footer_text = _(
+            '${footer_text} Page ${num1} of ${num2}',
+            mapping = {'footer_text': self.kofa_footer_text,
+                       'num1':self._pageNumber, 'num2':page_count})
+        self.drawRightString(
+            self.kofa_footer_x_pos, self.kofa_footer_y_pos,
+             translate(right_footer_text))
+        return
 
 class PDFCreator(grok.GlobalUtility):
@@ -281,8 +331,8 @@
             canvas.drawString(2.2*cm, 0.5 * inch,
                 translate(_(u'Date: ${a}', mapping = {'a': today})))
-        canvas.drawRightString(
-            width-2.2*cm, 0.5 * inch,
-            translate(_(u'${b} Page ${a}' , mapping = {'a':doc.page,
-                                                       'b':doc.kofa_footer})))
+        # set canves attributes needed to render `page x of y`
+        canvas.kofa_footer_x_pos = width-2.2*cm
+        canvas.kofa_footer_y_pos = 0.5 * inch
+        canvas.kofa_footer_text =  doc.kofa_footer
         canvas.restoreState()
         canvas.restoreState()
@@ -314,5 +364,7 @@
         doc.kofa_footer = footer
         doc.build(data, onFirstPage=self.paint_background,
-                  onLaterPages=self.paint_background)
+                  onLaterPages=self.paint_background,
+                  canvasmaker=NumberedCanvas
+                  )
         result = pdf_stream.getvalue()
         pdf_stream.close()
