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…