Problem

Need to generate QRCode and as many as possible BarCodes based on specific code.

Solution

After looking to several plugins like qrcode and barcode4j and after unsuccessful usage of them I’ve decided to do it myself and found out that it is easy enough.

Step 1 – Add necessary libs

After looking to several frameworks which allow generate BarCode for free I stopped on zxing as it support QRCode and several most used in the world BarCodes.
For the moment I used it version was 1.7 and supported BarCodes:

  • EAN_8
  • EAN_13
  • QR_CODE
  • UPC_A
  • CODE_39
  • CODE_128
  • ITF

Currently zxing 2.0 is already available, so probably that list of supported BarCodes extended.
Libs available in SonaType repository. I used two modules: core and javase.

Step 2 – Add Service to generate BarCodes

After libs are in place just create very simple Service like following:

Now you need to specify barcode format, data (number or text) and image size (width and height) and can easily render barcode from any taglib or controller like:

Add some AJAX if you want to reload BarCode on the fly…

4 comments on “QR Code and Bar Code rendering in Grails

  1. Hi, Just a notice that when I arrive at the homepage I keep getting send straight to this comment page, I’m really sure why but thought you would like to know Mainly on the home page) Best wishes

  2. Hi Michael,

    Thanks for sharing this! I’ve used your code, and currently, 2.0 is indeed available in the SonaType repo. Also, your code contains some unused code (the calculateMatrixSize method). What was the purpose of that method?

    Erik

Leave a Reply

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

*

1,854 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 REID Consulting Suffusion theme by Sayontan Sinha