[reportlab-users] Drawing QRcode

Tim Roberts timr at probo.com
Wed Aug 27 14:00:02 EDT 2014


Vaibhav Gajengi wrote:
>
> One more Q i want to ask about the rendering the pdf.
> i am using the below code snipet for rendering QR Code on the pdf but
> its not rendering the pdf on given x & y co-ordinates ?
> renderPDF.draw(d,p,x,y)
> is is there any reason for that ?
> Can you explain me the same ??

Where does it put it?  In the PostScript coordinate system, the (0,0)
point is at the bottom left-hand corner.  Y values increase as you go up
the page.  That's backwards from what you are used to (unless you worked
on OS/2, which is why Windows DIBs are also bottom-up).

Here is the complete code I tested with.  This produces a tiny QR code
near the bottom left corner (1 point from each margin):

    import os
    import sys
    from reportlab.pdfgen import canvas
    from reportlab.graphics.shapes import Drawing
    from reportlab.graphics.barcode.qr import QrCodeWidget
    from reportlab.graphics import renderPDF
    from reportlab.lib.units import mm

    p = canvas.Canvas('qrtest.pdf')
    unit = 10*mm

    qrw = QrCodeWidget('hello cruel world!')
    b = qrw.getBounds()
    w=b[2]-b[0]
    h=b[3]-b[1]
    d = Drawing(unit,unit,transform=[unit/w,0,0,unit/h,0,0])

    d.add(qrw)

    renderPDF.draw(d,p,1,1)
    p.showPage()
    p.save()


-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20140827/85531fd2/attachment.html>


More information about the reportlab-users mailing list