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…
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
Nice info! Keep it comin’!
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
Hi Erik,
Thanks for typos. I’ve updated the repo info and removed redundant code.