Re: Drawing QRcode

Tim Roberts <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Organization Providenza & Boekelheide, Inc.
Message-ID <[email protected]>
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, [email protected]
Providenza & Boekelheide, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.