Friday, February 24, 2012

Barcode: Professional java barcode API (reader & writer)

Originally Barcodes were 1D representation of data using width and spacing of bars. Common bar code types are UPC barcodes (as shown) which are seen on product packages. 

There are 2D barcodes as well (they are still called Barcodes even though they don’t use bars). A common example of 2D bar code is PDF417, QR Code (as shown) which is commonly used by mobile phone apps. You can read history and more info about Barcodes on Wikipedia..
QR Code
UPC-A
PDF417 code
There is an open source Java library called ‘zxing’ (Zebra Crossing) which can read and write many differently types of bar codes formats.
I tested zxing and it was able to read a pure barcode and embedded in the middle of a 100 dpi grayscale busy text document!
This article demonstrates how to use zxing to read and write bar codes from a Java program.
1- Getting the library
To download the source code and build the binaries, which was actually quite easy.

The source code of the library is available on Google Code. At the time of writing, 2.0 is the latest version of zxing.
  1. Download the release file ZXing-2.0.zip (which contains of mostly source files) from here.
  2. Unzip the file in a local directory
  3. You will need to build 2 jar files from the downloaded source: core.jar, javase.jar
2- Including the libraries in your project
If you are using ant or normal project, add the core.jar and javase.jar to your project’s classpath.
Once you have the jars included in your project’s classpath, you are now ready to read and write barcodes from java!

Below is an example using the zxing API as generic way of reading and writing any type of barcodes, and improve this engine with hints passed to encoder or decoder methods.

3- Reading a Bar Code


You can read the bar code by first loading the image as an input stream and then calling this utility method.



4- Writing a Bar Code

You can encode a small text string as follows:

5- JavaDocs & documentation help

The Javadocs are part of the downloaded zip file. You can find a list of supported bar code formats in the Javadocs.
Update (2/2/2013):
Hi Please find the below link contains the full explanation of barcode API. Developing advanced Barcode applications using "BarcodeEngine" library
If you need any other help leave your comments, it will be nice if you leave your Reactions.