Re: Performance Issue generating multiple QR codes

Andy Robinson <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CABjtAptpCTh-ybJ78BAkLX4R7CVucLi5CM+ibTNAJHyahU1+zg@mail.gmail.com>
That's interesting.  We will try to do a little profiling at some
point, although not sure we will have time this week, and take a look
at how the other package does it.

- Andy


On 17 September 2014 20:18, Thomas Kremmel <[email protected]> wrote:
> ah yes - and the bottleneck was not the qr code data generation, but
> reportlab printing the qr code. it seems as it is quite a challenge for
> reportlab to render the qr code when using QrCodeWidget. But rending .pngs
> is super fast! Thus I would recommend rendering QR code images.
>
> Best regards,
> Thomas
>
> 2014-09-17 21:15 GMT+02:00 Thomas Kremmel <[email protected]>:
>>
>> > Seriously?  You have a QR block that covers 40 square inches?  Will QR
>> > scanners read that?
>>
>> Yeah, they can read it quite easily.
>>
>>
>> For the record. I switched to generating the QR data as a .png and
>> rendering the resulting .png into the .pdf. Brings down the 20 seconds to 2.
>> :)
>>
>> Here is the code, using https://pypi.python.org/pypi/qrcode instead of the
>> reportlab QrCodeWidget .
>>
>> qr = qrcode.QRCode(
>>             version=1,
>>             error_correction=qrcode.constants.ERROR_CORRECT_L,
>>             box_size=10,
>>             border=4,
>>         )
>>         qr.add_data(qr_code_data)
>>         qr.make(fit=True)
>>         qr_img = qr.make_image()
>>
>>         # create a byte stream
>>         output = io.BytesIO()
>>         # put image data into byte stream
>>         qr_img.save(output)
>>         # set byte stream to first read position
>>         output.seek(0)
>>         # create reportlab image with byte stream
>>         rl_img = Image(output, width=10*cm, height=10*cm)
>>
>>         self.pdf.img(rl_img)
>>
>> 2014-09-17 19:43 GMT+02:00 Tim Roberts <[email protected]>:
>>>
>>> Thomas Kremmel wrote:
>>> > Hello,
>>> >
>>> > I'm using Reportlab to generate a pdf with 10 pages. I print on each
>>> > page a QR code, which is about half the size of the A4 page.
>>>
>>> Seriously?  You have a QR block that covers 40 square inches?  Will QR
>>> scanners read that?
>>>
>>>
>>> > The generation of the .pdf takes me about 20 seconds.
>>> > When I generate the .pdf without the QR codes the .pdf is generated
>>> > immediately. Thus it is obvious that the pdf generation of the QR
>>> > codes consumes the most time.
>>> >
>>> > Any idea what I could do here to bring this down to an user acceptable
>>> > time - say 2 seconds.
>>>
>>> Generating a QR code is computationally expensive.  There's no two ways
>>> about it.  It's a recursive algorithm with lots of mathematics.  If this
>>> is a problem for you, you could try to rewrite part of the algorithm in
>>> C++, but it would be tricky to integrate that with the Python code.
>>>
>>> --
>>> Tim Roberts, [email protected]
>>> Providenza & Boekelheide, Inc.
>>>
>>> _______________________________________________
>>> reportlab-users mailing list
>>> [email protected]
>>> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>>
>>
>
>
> _______________________________________________
> reportlab-users mailing list
> [email protected]
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>



-- 
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420
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.