Index: /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
===================================================================
--- /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py	(revision 12050)
+++ /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py	(revision 12051)
@@ -692,4 +692,19 @@
         return
 
+class CustomerBasePDFFormPage(IkobaDisplayFormPage):
+    """ Page to display customer base data in pdf files.
+    """
+
+    def __init__(self, context, request, omit_fields=()):
+        self.omit_fields = omit_fields
+        super(CustomerBasePDFFormPage, self).__init__(context, request)
+
+    @property
+    def form_fields(self):
+        form_fields = grok.AutoFields(ICustomer)
+        for field in self.omit_fields:
+            form_fields = form_fields.omit(field)
+        return form_fields
+
 # Pages for customer documents
 
@@ -915,2 +930,30 @@
             wf_info.fireTransition(transition_id)
         return
+
+class ExportPDFDocumentsOverviewPage(UtilityView, grok.View):
+    """Deliver an overview slip.
+    """
+    grok.context(ICustomer)
+    grok.name('overview_slip.pdf')
+    grok.require('waeup.viewCustomer')
+    prefix = 'form'
+
+    omit_fields = ('suspended', 'sex', 'suspended_comment')
+
+    form_fields = None
+
+    @property
+    def label(self):
+        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
+        return translate(_('Documents of'),
+            'waeup.ikoba', target_language=portal_language) \
+            + ' %s' % self.context.display_fullname
+
+    def render(self):
+        customerview = CustomerBasePDFFormPage(self.context,
+            self.request, self.omit_fields)
+        customers_utils = getUtility(ICustomersUtils)
+        return customers_utils.renderPDF(
+            self, 'overview_slip.pdf',
+            self.context, customerview,
+            omit_fields=self.omit_fields)
Index: /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
===================================================================
--- /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12050)
+++ /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12051)
@@ -44,4 +44,5 @@
 from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
 from waeup.ikoba.documents.workflow import VERIFIED
+from waeup.ikoba.browser.tests.test_pdf import samples_dir
 
 PH_LEN = 15911  # Length of placeholder file
@@ -504,4 +505,5 @@
             'temp_password generated: %s' % temp_password in logcontent)
 
+
 class CustomerUITests(CustomersFullSetup):
     # Tests for Customer class views and pages
@@ -797,5 +799,5 @@
 
 
-class CustomerDocumentUITests(CustomersFullSetup):
+class DocumentUITests(CustomersFullSetup):
     # Tests for CustomerDocument relates views and pages
 
@@ -980,2 +982,13 @@
         self.assertTrue('Only the following extensions are allowed'
             in self.browser.contents)
+
+
+    def test_view_slips(self):
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        # Officers can open the pdf transcript
+        self.browser.open(self.customer_path + '/overview_slip.pdf')
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
+        path = os.path.join(samples_dir(), 'overview_slip.pdf')
+        open(path, 'wb').write(self.browser.contents)
+        print "Sample PDF overview_slip.pdf written to %s" % path
Index: /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py
===================================================================
--- /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py	(revision 12050)
+++ /main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py	(revision 12051)
@@ -21,7 +21,22 @@
 import os
 import grok
+from reportlab.lib import colors
+from reportlab.lib.units import cm
+from reportlab.lib.pagesizes import A4
+from reportlab.lib.styles import getSampleStyleSheet
+from reportlab.platypus import Paragraph, Image, Table, Spacer
+from zope.event import notify
+from zope.schema.interfaces import ConstraintNotSatisfied
+from zope.component import getUtility, createObject
+from zope.formlib.form import setUpEditWidgets
+from zope.i18n import translate
 from waeup.ikoba.interfaces import MessageFactory as _
-from waeup.ikoba.interfaces import CREATED, STARTED, REQUESTED, APPROVED
+from waeup.ikoba.interfaces import (
+    CREATED, STARTED, REQUESTED, APPROVED, IIkobaUtils, IExtFileStore)
 from waeup.ikoba.customers.interfaces import ICustomersUtils
+from waeup.ikoba.browser.interfaces import IPDFCreator
+from waeup.ikoba.browser.pdf import (
+    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
+    get_signature_tables, get_qrcode)
 
 RE_CUSTID_NON_NUM = re.compile('[^\d]+')
@@ -69,4 +84,186 @@
     return folder_name
 
+SLIP_STYLE = [
+    ('VALIGN',(0,0),(-1,-1),'TOP'),
+    #('FONT', (0,0), (-1,-1), 'Helvetica', 11),
+    ]
+
+CONTENT_STYLE = [
+    ('VALIGN',(0,0),(-1,-1),'TOP'),
+    #('FONT', (0,0), (-1,-1), 'Helvetica', 8),
+    #('TEXTCOLOR',(0,0),(-1,0),colors.white),
+    #('BACKGROUND',(0,0),(-1,0),colors.black),
+    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
+    ('BOX', (0,0), (-1,-1), 1, colors.black),
+
+    ]
+
+FONT_SIZE = 10
+FONT_COLOR = 'black'
+
+def trans(text, lang):
+    # shortcut
+    return translate(text, 'waeup.kofa', target_language=lang)
+
+
+def formatted_text(text, color=FONT_COLOR, lang='en'):
+    """Turn `text`, `color` and `size` into an HTML snippet.
+
+    The snippet is suitable for use with reportlab and generating PDFs.
+    Wraps the `text` into a ``<font>`` tag with passed attributes.
+
+    Also non-strings are converted. Raw strings are expected to be
+    utf-8 encoded (usually the case for widgets etc.).
+
+    Finally, a br tag is added if widgets contain div tags
+    which are not supported by reportlab.
+
+    The returned snippet is unicode type.
+    """
+    if not isinstance(text, unicode):
+        if isinstance(text, basestring):
+            text = text.decode('utf-8')
+        else:
+            text = unicode(text)
+    if text == 'None':
+        text = ''
+    # Mainly for boolean values we need our customized
+    # localisation of the zope domain
+    text = translate(text, 'zope', target_language=lang)
+    text = text.replace('</div>', '<br /></div>')
+    tag1 = u'<font color="%s">' % (color)
+    return tag1 + u'%s</font>' % text
+
+def render_customer_data(customerview, context, omit_fields=(),
+                        lang='en', slipname=None):
+    """Render customer table for an existing frame.
+    """
+    width, height = A4
+    set_up_widgets(customerview, ignore_request=True)
+    data_left = []
+    data_middle = []
+    style = getSampleStyleSheet()
+    img = getUtility(IExtFileStore).getFileByContext(
+        customerview.context, attr='passport.jpg')
+    if img is None:
+        from waeup.ikoba.browser import DEFAULT_PASSPORT_IMAGE_PATH
+        img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')
+    doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound')
+    data_left.append([doc_img])
+    #data.append([Spacer(1, 12)])
+
+    f_label = trans(_('Name:'), lang)
+    f_label = Paragraph(f_label, ENTRY1_STYLE)
+    f_text = formatted_text(customerview.context.display_fullname)
+    f_text = Paragraph(f_text, ENTRY1_STYLE)
+    data_middle.append([f_label,f_text])
+
+    for widget in customerview.widgets:
+        if 'name' in widget.name:
+            continue
+        f_label = translate(
+            widget.label.strip(), 'waeup.ikoba',
+            target_language=lang)
+        f_label = Paragraph('%s:' % f_label, ENTRY1_STYLE)
+        f_text = formatted_text(widget(), lang=lang)
+        f_text = Paragraph(f_text, ENTRY1_STYLE)
+        data_middle.append([f_label,f_text])
+
+    if getattr(customerview.context, 'certcode', None):
+        if not 'date_of_birth' in omit_fields:
+            f_label = trans(_('Date of Birth:'), lang)
+            f_label = Paragraph(f_label, ENTRY1_STYLE)
+            date_of_birth = customerview.context.date_of_birth
+            tz = getUtility(IIkobaUtils).tzinfo
+            date_of_birth = to_timezone(date_of_birth, tz)
+            if date_of_birth is not None:
+                date_of_birth = date_of_birth.strftime("%d/%m/%Y")
+            f_text = formatted_text(date_of_birth)
+            f_text = Paragraph(f_text, ENTRY1_STYLE)
+            data_middle.append([f_label,f_text])
+
+    # append QR code to the right
+    if slipname:
+        url = customerview.url(context, slipname)
+        data_right = [[get_qrcode(url, width=70.0)]]
+        table_right = Table(data_right,style=SLIP_STYLE)
+    else:
+        table_right = None
+
+    table_left = Table(data_left,style=SLIP_STYLE)
+    table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm])
+    table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE)
+    return table
+
+def render_table_data(tableheader, tabledata, lang='en'):
+    """Render children table for an existing frame.
+    """
+    data = []
+    #data.append([Spacer(1, 12)])
+    line = []
+    style = getSampleStyleSheet()
+    for element in tableheader:
+        field = '<strong>%s</strong>' % formatted_text(element[0], lang=lang)
+        field = Paragraph(field, style["Normal"])
+        line.append(field)
+    data.append(line)
+    for ticket in tabledata:
+        line = []
+        for element in tableheader:
+              field = formatted_text(getattr(ticket,element[1],u' '))
+              field = Paragraph(field, style["Normal"])
+              line.append(field)
+        data.append(line)
+    table = Table(data,colWidths=[
+        element[2]*cm for element in tableheader], style=CONTENT_STYLE)
+    return table
+
+def docs_as_flowables(view, lang='en'):
+    """Create reportlab flowables out of scanned docs.
+    """
+    # XXX: fix circular import problem
+    from waeup.ikoba.customers.fileviewlets import FileManager
+    from waeup.ikoba.browser import DEFAULT_IMAGE_PATH
+    style = getSampleStyleSheet()
+    data = []
+
+    # Collect viewlets
+    fm = FileManager(view.context, view.request, view)
+    fm.update()
+    if fm.viewlets:
+        sc_translation = trans(_('Scanned Documents'), lang)
+        data.append(Paragraph(sc_translation, HEADING_STYLE))
+        # Insert list of scanned documents
+        table_data = []
+        for viewlet in fm.viewlets:
+            if viewlet.file_exists:
+                # Show viewlet only if file exists
+                f_label = Paragraph(trans(viewlet.label, lang), ENTRY1_STYLE)
+                img_path = getattr(getUtility(IExtFileStore).getFileByContext(
+                    view.context, attr=viewlet.download_name), 'name', None)
+                #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE)
+                if img_path is None:
+                    pass
+                elif not img_path[-4:] in ('.jpg', '.JPG'):
+                    # reportlab requires jpg images, I think.
+                    f_text = Paragraph('%s (not displayable)' % (
+                        viewlet.title,), ENTRY1_STYLE)
+                else:
+                    f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound')
+                table_data.append([f_label, f_text])
+        if table_data:
+            # safety belt; empty tables lead to problems.
+            data.append(Table(table_data, style=SLIP_STYLE))
+    return data
+
+
+def set_up_widgets(view, ignore_request=False):
+    view.adapters = {}
+    view.widgets = setUpEditWidgets(
+        view.form_fields, view.prefix, view.context, view.request,
+        adapters=view.adapters, for_display=True,
+        ignore_request=ignore_request
+        )
+
 class CustomersUtils(grok.GlobalUtility):
     """A collection of methods subject to customization.
@@ -90,2 +287,94 @@
         APPROVED: _('approved'),
         }
+
+    def getPDFCreator(self, context=None):
+        """Get a pdf creator suitable for `context`.
+
+        The default implementation always returns the default creator.
+        """
+        return getUtility(IPDFCreator)
+
+    def renderPDF(self, view, filename='slip.pdf', customer=None,
+                  customerview=None,
+                  tableheader=[], tabledata=[],
+                  note=None, signatures=None, sigs_in_footer=(),
+                  show_scans=True, show_history=True, topMargin=1.5,
+                  omit_fields=()):
+        """Render pdf slips for various pages.
+        """
+        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
+        style = getSampleStyleSheet()
+        creator = self.getPDFCreator()
+        data = []
+        doc_title = view.label
+        author = '%s (%s)' % (view.request.principal.title,
+                              view.request.principal.id)
+        footer_text = view.label.split('\n')
+        if len(footer_text) > 2:
+            # We can add a department in first line
+            footer_text = footer_text[1]
+        else:
+            # Only the first line is used for the footer
+            footer_text = footer_text[0]
+        if getattr(customer, 'customer_id', None) is not None:
+            footer_text = "%s - %s - " % (customer.customer_id, footer_text)
+
+        # Insert customer data table
+        if customer is not None:
+            bd_translation = trans(_('Base Data'), portal_language)
+            data.append(Paragraph(bd_translation, HEADING_STYLE))
+            data.append(render_customer_data(
+                customerview, view.context, omit_fields, lang=portal_language,
+                slipname=filename))
+
+        # Insert widgets
+        if view.form_fields:
+            data.append(Paragraph(view.title, HEADING_STYLE))
+            separators = getattr(self, 'SEPARATORS_DICT', {})
+            table = creator.getWidgetsTable(
+                view.form_fields, view.context, None, lang=portal_language,
+                separators=separators)
+            data.append(table)
+
+        # Insert scanned docs
+        if show_scans:
+            data.extend(docs_as_flowables(view, portal_language))
+
+        # Insert history
+        if show_history:
+            hist_translation = trans(_('Workflow History'), portal_language)
+            data.append(Paragraph(hist_translation, HEADING_STYLE))
+            data.extend(creator.fromStringList(customer.history.messages))
+
+        # Insert content tables (optionally on second page)
+        if hasattr(view, 'tabletitle'):
+            for i in range(len(view.tabletitle)):
+                if tabledata[i] and tableheader[i]:
+                    #data.append(PageBreak())
+                    #data.append(Spacer(1, 20))
+                    data.append(Paragraph(view.tabletitle[i], HEADING_STYLE))
+                    data.append(Spacer(1, 8))
+                    contenttable = render_table_data(tableheader[i],tabledata[i])
+                    data.append(contenttable)
+
+        # Insert signatures
+        # XXX: We are using only sigs_in_footer in waeup.ikoba, so we
+        # do not have a test for the following lines.
+        if signatures and not sigs_in_footer:
+            data.append(Spacer(1, 20))
+            # Render one signature table per signature to
+            # get date and signature in line.
+            for signature in signatures:
+                signaturetables = get_signature_tables(signature)
+                data.append(signaturetables[0])
+
+        view.response.setHeader(
+            'Content-Type', 'application/pdf')
+        try:
+            pdf_stream = creator.create_pdf(
+                data, None, doc_title, author=author, footer=footer_text,
+                note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin)
+        except IOError:
+            view.flash('Error in image file.')
+            return view.redirect(view.url(view.context))
+        return pdf_stream
