Changeset 10595 for main


Ignore:
Timestamp:
6 Sep 2013, 13:12:27 (11 years ago)
Author:
uli
Message:

Add helper function to generate a flowable QR code for reportlab.

File:
1 edited

Legend:

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

    r10571 r10595  
    2424from cStringIO import StringIO
    2525from datetime import datetime
     26from reportlab.graphics.barcode.qr import QrCodeWidget
     27from reportlab.graphics.shapes import Drawing
    2628from reportlab.lib import colors
    2729from reportlab.lib.units import cm, inch, mm
     
    3941from waeup.kofa.interfaces import IKofaUtils
    4042from waeup.kofa.interfaces import MessageFactory as _
     43
    4144
    4245#: A reportlab paragraph style for 'normal' output.
     
    850853    grok.name('landscape')
    851854    pagesize = landscape(A4)
     855
     856def get_qrcode(text, width=60.0):
     857    """Get a QR Code as Reportlab Flowable (actually a `Drawing`).
     858
     859    `width` gives box width in pixels (I think)
     860    """
     861    widget = QrCodeWidget(text)
     862    bounds = widget.getBounds()
     863    w_width = bounds[2] - bounds[0]
     864    w_height = bounds[3] - bounds[1]
     865    drawing = Drawing(
     866        width, width,
     867        transform=[width/w_width, 0, 0, width/w_height, 0, 0])
     868    drawing.add(widget)
     869    return drawing
Note: See TracChangeset for help on using the changeset viewer.