Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barcode generation in java

I am making an application to generate barcodes, but it does not give me the barcode: the application returns the text that I have provided. My code is:

Code39 code39=new Code39();
String outputStr=code39.encode("12345678", 1);
String humanTextStr=code39.getHumanText();
jLabel1.setText(outputStr);
jLabel1.setFont(new java.awt.Font("CCode39_S3",java.awt.Font.PLAIN,24));

Please can anyone tell me why this happens?

like image 803
Jayashri Avatar asked Jul 15 '12 03:07

Jayashri


People also ask

How do you generate and read QR codes in Java?

To generate a QR code in Java, we need to use a third-party library named ZXing (Zebra Crossing). It is a popular API that allows us to process with QR code. With the help of the library, we can easily generate and read the QR code.

What is a barcode generator?

The barcode generator allows you to create a barcode graphic by providing barcode symbology and data. Click on the Generate Barcode to create a graphic containing your barcode. Right click to copy or save the barcode, then paste or insert the barcode into your document.


2 Answers

Your application is returning a text because you have told it to get the text not the bar-code.

Try the following code:

a=jTextField24.getText();      
Code39 barcode=new Code39();      
barcode.setData(a);      
ImageIcon icon = new ImageIcon(barcode.drawBarcode());          
jLabel34.setIcon(icon);
like image 67
Nitesh Verma Avatar answered Sep 19 '22 11:09

Nitesh Verma


Try using open source libraries for generating barcodes in java. For e.g., iText or http://barbecue.sourceforge.net/

Please refer to this link as well BarCode Image Generator in Java

Hope it helps.

like image 44
krishnakumarp Avatar answered Sep 19 '22 11:09

krishnakumarp