Index: main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py	(revision 8081)
+++ main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py	(revision 8091)
@@ -56,15 +56,4 @@
             ar_translation, self.context.application_number)
 
-    def _setUpWidgets(self):
-        """Setup simple display widgets.
-
-        Returns the list of widgets.
-        """
-        request = TestRequest()
-        return setUpEditWidgets(
-            self.form_fields, 'form', self.context, request, {},
-            for_display=True, ignore_request=True
-            )
-
     def _getCourseAdmittedLink(self, view):
         """Return link, title and code in html format to the certificate
@@ -79,101 +68,18 @@
         return ''
 
-    def _addPassportImage(self, data):
-        """Add passport image to data stream.
+    def _getDeptAndFaculty(self):
+        """Return long titles of department and faculty.
 
-        If no image exists yet the default image is added.
+        Returns a list [department_title, faculty_title]
+
+        If the context applicant has no course admitted or dept. and
+        faculty cannot be determined, ``None`` is returned.
         """
-        img = getUtility(IExtFileStore).getFileByContext(self.context)
-        if img is None:
-            img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')
-        doc_img = Image(img.name, width=4*cm, height=3*cm, kind='bound')
-        data.append([doc_img])
-        data.append([Spacer(1, 18)])
-        return data
-
-    def _addDeptAndFaculty(self, data):
-        """If we have a valid course admitted, add dept. and faculty to data
-           stream.
-        """
-        style = getSampleStyleSheet()
         course_admitted = self.context.course_admitted
         dept = getattr(
                 getattr(course_admitted, '__parent__', None),
                 '__parent__', None)
-        if dept is None:
-            return data
-        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
-        dp_translation = translate(_('Department:'),
-            'waeup.kofa', target_language=portal_language)
-        f_label = '<font size=12>%s</font>' % dp_translation
-        f_text = '<font size=12>%s</font>' % dept.longtitle()
-        f_label = Paragraph(f_label, style["Normal"])
-        f_text = Paragraph(f_text, style["Normal"])
-        data.append([f_label,f_text])
-
         faculty = getattr(dept, '__parent__', None)
-        if faculty is None:
-            return data
-        fc_translation = translate(_('Faculty:'),
-            'waeup.kofa', target_language=portal_language)
-        f_label = '<font size=12>%s</font>' % fc_translation
-        f_text = '<font size=12>%s</font>' % faculty.longtitle()
-        f_label = Paragraph(f_label, style["Normal"])
-        f_text = Paragraph(f_text, style["Normal"])
-        data.append([f_label,f_text])
-        return data
-
-    def _getWidgetsTable(self, view):
-        """Return a reportlab table buildt of widgets.
-        """
-        style = getSampleStyleSheet()
-        table_data = []
-        table_style = [('LEFTPADDING', (0,0), (0,-1), 0),
-                       ('VALIGN', (0,0), (-1,-1), 'TOP'),
-                       ]
-        row_num = 0
-        widgets = self._setUpWidgets()
-        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
-        for widget in widgets:
-            separators = getUtility(IApplicantsUtils).SEPARATORS_DICT
-            if separators and separators.get(widget.name):
-                f_headline = ('<font size=12><strong>%s</strong></font>'
-                    % translate(separators[widget.name], 'waeup.kofa',
-                    target_language=portal_language))
-                f_headline = Paragraph(f_headline, style["Normal"])
-                table_data.append([f_headline ])
-                table_style.append(('SPAN', (0,row_num), (-1,row_num)),)
-                table_style.append(
-                    ('TOPPADDING', (0,row_num), (-1,row_num), 12),)
-                row_num += 1
-            f_label = '<font size=12>%s</font>:' % translate(
-                widget.label.strip(), 'waeup.kofa',
-                target_language=portal_language)
-            f_label = Paragraph(f_label, style["Normal"])
-            f_text = '<font size=12>%s</font>' % widget()
-            # Add br tag if widgets contain div tags
-            # which are not supported by reportlab
-            f_text = f_text.replace('</div>', '</div><br />')
-            f_text = f_text.replace('\n', '')
-            f_text = Paragraph(f_text, style["Normal"])
-            table_data.append([f_label,f_text])
-            row_num += 1
-        adm_translation = translate(_('Admitted Course of Study:'),
-                'waeup.kofa', target_language=portal_language)
-        f_label = '<font size=12>%s</font>' % adm_translation
-        f_text = '<font size=12>%s</font>' % (
-            self._getCourseAdmittedLink(view),)
-        f_label = Paragraph(f_label, style["Normal"])
-        f_text = Paragraph(f_text, style["Normal"])
-        table_data.append([f_label,f_text])
-        row_num += 1
-
-        # Add dept. and faculty if applicable
-        table_data = self._addDeptAndFaculty(table_data)
-
-        # Create table
-        table = Table(table_data,style=table_style)
-        table.hAlign = 'LEFT'
-        return table
+        return [x is not None and x.longtitle() or x for x in dept, faculty]
 
     def _addComments(self, data):
@@ -205,13 +111,13 @@
         principal.
         """
-        doc_title = self.title.replace('-', '\n')
+        doc_title = '\n'.join([x.strip() for x in self.title.split('-')])
         style = getSampleStyleSheet()
         data = []
+        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
+        separators = getUtility(IApplicantsUtils).SEPARATORS_DICT
+        creator = getUtility(IPDFCreator)
 
         # append history
-        for msg in self.context.history.messages:
-            f_msg = '<font face="Courier" size=10>%s</font>' % msg
-            data.append(Paragraph(f_msg, style["Normal"]))
-        data.append(Spacer(1, 20))
+        data.extend(creator.fromStringList(self.context.history.messages))
 
         # append photograph
@@ -219,14 +125,17 @@
             getUtility(IExtFileStore).getFileByContext(self.context),
             'name', DEFAULT_PASSPORT_IMAGE_PATH)
-        doc_img = Image(img_path, width=4*cm, height=3*cm, kind='bound')
-        doc_img.hAlign='LEFT'
-        data.append(doc_img)
+        data.append(creator.getImage(img_path))
+        data.append(Spacer(1, 12))
 
         # append widgets
-        data.append(self._getWidgetsTable(view))
+        dept, faculty = self._getDeptAndFaculty()
+        data.append(creator.getWidgetsTable(
+            self.form_fields, self.context, view, lang=portal_language,
+            domain='waeup.kofa', separators=separators,
+            course_label='Admitted Course of Study:',
+            course_link=self._getCourseAdmittedLink(view),
+            dept=dept, faculty=faculty))
 
         # append comments
         data = self._addComments(data)
-
-        creator = getUtility(IPDFCreator)
         return creator.create_pdf(data, None, doc_title)
