How can I create a barcode image in Java? I need something that will allow me to enter a number and produce the corresponding barcode image. Is there a free library available for this type of task?
5 Answers
iText is a great Java PDF library. They also have an API for creating barcodes. You don't need to be creating a PDF to use it.
This page has the details on creating barcodes. Here is an example from that site:
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
The biggest thing you will need to determine is what type of barcode you need. There are many different barcode formats and iText does support a lot of them. You will need to know what format you need before you can determine if this API will work for you.

- 25,715
- 9
- 65
- 74
-
@Chris Dail. Iwould like to clear my doubt. Is iText is free? can we use it for commercial projects – xrcwrn Oct 21 '13 at 04:58
-
@Manish iText used to be free. It looks like it now requires a commercial license for commercial products. – Chris Dail Oct 25 '13 at 18:47
-
@ChrisDail I am developing a software product for sale. Can I use iText for free – xrcwrn Oct 26 '13 at 06:03
-
The problem is the iText barcode AWT image creator doesn't support options like text, or changing the width. You can do this for the PDF output but not AWT. – sksamuel Sep 08 '14 at 17:46
-
I'm wondering how you can suggest using iText without mentioning the implications the AGPL has.. – Dominik Dorn Jun 01 '16 at 10:13
-
According to their page iText com.lowagie classes has been deprecated in 2012. And seems it no longer an open API. – vicco Mar 27 '19 at 03:07
There is also this free API that you can use to make free barcodes in java.

- 1,889
- 5
- 20
- 33
-
Barbecue is only dependent on JDOM.. looked at it and Barcode4J, but didn't really like adding an Avalon dependency :-/ – Thomas W Jun 27 '12 at 04:16
-
Barcode4J is dependent on Avalon.. requires it for configuration at startup. Barbecue is only dependent on JDOM. – Thomas W Jun 27 '12 at 04:17
-
10Avalon Framework is only needed if you want to configure Barcode4J using XML. If you work with [plain Java](http://barcode4j.sourceforge.net/latest/embedding-bean.html), it doesn't require JDOM nor Avalon. – Jeremias Märki Jul 16 '12 at 07:22
-
It seems like Barcode4j only supports a subset of all available barcode formats when using beans. Also Avalon framework had been retired for a whie. Barbecue is still in beta with no updates since 2007. Things don't look promising. – Andras Balázs Lajtha Feb 05 '17 at 16:53
ZXing is a free open source Java library to read and generate barcode images. You need to get the source code and build the jars yourself. Here's a simple tutorial that I wrote for building with ZXing jars and writing your first program with ZXing.

- 358
- 2
- 5
-
1Is available on maven central. of the recommendations given, this appears to be (by a huge margin), the best choice. – Liam M Jan 02 '18 at 02:53
I use
barbeque
, it's great, and supports a very wide range of different barcode formats.
See if you like
its API
.
Sample API:
public static Barcode createCode128(java.lang.String data) throws BarcodeException
Creates a Code 128 barcode that dynamically switches between character sets to give the smallest possible encoding. This will encode all numeric characters, upper and lower case alpha characters and control characters from the standard ASCII character set. The size of the barcode created will be the smallest possible for the given data, and use of this "optimal" encoding will generally give smaller barcodes than any of the other 3 "vanilla" encodings.

- 27,371
- 47
- 154
- 243