QR Code on PDF Documents for Identification and Detection on Server Side

12 / Aug / 2010 by Vivek Krishna 0 comments

In one of our projects, we needed to include QR Code on the PDF documents, which were to be sent out to the user and the printed version was to be received back from them. Once the documents were received, we were going to scan each sheet into an image file and then, these files were going to be read by the grails application, identify the digital copy of the document and set a “received” status on the domain class representing the document.

Grails QR Code plugin proved to be an excellent choice to generate QR Codes to be included in the document, however, we were using iText Renderer, which meant that we had to provide the absolute URL to the image stream. This was accomplished by providing a URL, which was similar to

${createLink(controller: 'qrcode', action: 'text', absolute: true, params: [text: 'Text to be Encoded'])}

instead of using the the tags provided by the plugin. Ability to set the property ‘absolute’ while creating links is one of the features I would love to see in the QRCode tag library.

Once the hard copies of the documents were received, we were going to scan them and upload them to our grails application. There are many desktop utilities available for detecting QR Code on images, but no ready made solution for a web application.

A library which we found useful, however,  was zxing hosted on Google Code. This had a command line tool and the wiki also suggested possible ways to use the library within a java application.

What we did was to read the image using the javax.imageio.ImageIO.read() method (this takes in only a file, so we ended up writing the uploaded file temporarily on the disk and then read it) and then decode the qrcode as:

        com.google.zxing.Reader reader = new QRCodeReader()
        java.awt.image.BufferedImage image = ImageIO.read(imageFile)
        com.google.zxing.LuminanceSource source = new com.google.zxing.client.j2se.BufferedImageLuminanceSource(image);
        com.google.zxing.BinaryBitmap bitmap = new com.google.zxing.BinaryBitmap(new com.google.zxing.common.HybridBinarizer(source))
        Result result = reader.decode(bitmap)
        return result.text

This returns the text, which was embedded in the QR Code.

Hope this helps



Leave a Reply

Your email address will not be published. Required fields are marked *