Ignore:
Timestamp:
1 Oct 2020, 06:51:10 (4 years ago)
Author:
Henrik Bettermann
Message:

Use Uli's marker substitution hack to inject signature
images into pdf files.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/browser
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py

    r16149 r16262  
    2323import os
    2424import pytz
     25from string import Template
    2526from cStringIO import StringIO
    2627from datetime import datetime
     
    559560    logo_left_pos = [0, 0, 0]
    560561    pagesize = portrait(A4)
     562
     563    test_signature_img_path = os.path.join(
     564        os.path.dirname(__file__), 'static', 'test_signature.png')
    561565
    562566    @classmethod
     
    823827        return
    824828
     829    def _substitute_markers(self, text):
     830        """If `text` contains some marker, substitute it.
     831
     832        Markers are standard library string template placeholders. See
     833        https://docs.python.org/2/library/string.html and
     834        `string.Template` for details. Roughly, placeholders look like
     835        ``${some_marker}``.
     836
     837        Valid markers:
     838           ``test_signature_img_path`` -- path to signature image stored in
     839                                     `test_signature_img_path`` attribute.
     840        """
     841        text = Template(text)
     842        PDF_SIGNATURES =  {
     843            'test_signature_img_path': self.test_signature_img_path,
     844            }
     845        return text.safe_substitute(PDF_SIGNATURES)
     846
    825847    def create_pdf(self, data, headerline=None, title=None, author=None,
    826848                   footer='', note=None, sigs_in_footer=[], topMargin=1.5,
     
    849871        doc.letterhead_path = letterhead_path
    850872        if note is not None:
     873            # Inject signature images
     874            note = self._substitute_markers(note)
     875            # Format html
    851876            html = format_html(note)
    852877            data.append(Paragraph(html, NOTE_STYLE))
Note: See TracChangeset for help on using the changeset viewer.