How to convert digits, text string to barcodes using Java?


How to convert digits, text, ASCII, Unicode string, GS1 data to barcodes using Java Barcode library?

Create GS1 compatible barcodes and encode Unicode into barcodes for Java programs

  • Easy to integrate java barcode library (jar) to encode GS1 barcodes images
  • Create GS1-compatible QR Code, Data Matrix, ITF-14, EAN-128, and GS1 Databar in Java
  • Compatible with the latest GS1 & ISO / IEC barcode specifications
  • Unicode support for easily encoding barcodes with non-English character sets
  • Java class sample code provided to ensure valid barcode data input
  • Capable of printing & embedding barcodes in Jasper Report, iReport, Eclipse BIRT Report
  • API with simple examples to create GS1 barcodes in html JSP pages, Servlet, J2EE web applications
  • Mature Java barcode SDK with a variety of developer licenses to select from


How to convert text to barcode in Java web, desktop application?

  1. Download Java Barcode Generator library
  2. Install Java barcode generation library jar file into Java project
  3. Start to Create










Java Barcode Generator is a mature Java Barcode Library SDK (jar files) which enables developers to easily generate over 30 linear & 2D (two-dimensional) barcode types in Java programs, including major GS1, ISO/IEC, postal barcodes. With this Java barcode jar, users can stream barcodes in Java Server Side projects like JSP, Java Servlet, apart from Java Class, Jasper Report, and Eclipse BIRT, Oracle Report. Besides, the intuitive interface provides full features & flexible functions for barcode control & design.
OnBarcode also provides other Java tutorials for barcode implementation:
  1. Java Barcode Generator Tutorial - How to generate & draw barcode images in Java applications programmatically
  2. Java Class Barcode Tutorial - How to stream & create barcode graphics in Java Class Library with free barcoder trial download
  3. Java Servlet Barcode Tutorial - How to create & display barcodes in Java web applications (JSP Servlet) or website
  4. iReport Barcode Tutorial - How to print & embed barcode image labels in iReport via java programming step by step


How to convert digits, text to barcode in Java class?

Top
All 1d and 2d barcode formats support number (digits) data encoding, and most of the popular barcode formats support plain text encoding also.

The following Java code explains how to generate a Code 128 barcode with number and string text encoded using Java.
  • Create a Code 128 barcode object using class Code128
  • Set the encoding text string with digits and characters using method setData()
  • Generate and print barcode to an image file
Code128 barcode = new Code128();
barcode.setData("Code-128");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-number-text.png");





How to convert ASCII characters to barcode in Java class?

Top
The full ASCII table includes 128 characters. There are 95 printable characters and 33 control characters (non-printing chars).

You can directly input the printable 95 ASCII characters using method setData() using Java Barcode Generator library. However you cannot directly input the non-printable characters in Java IDE code editor.

The following barcode formats support full 128 ASCII characters encoding
  • Code 128
  • Code 39 extension mode
  • Data Matrix
  • PDF417
  • QR Code
Here we will show you how to encode non-printing ASCII characters in Java class.
  • Enable process tilde setProcessTilde(true) to handle special characters, such as non-printing chars
  • Convert each non-printing char's ASCII byte value to a three-digit string, and add '~' in the beginning of the each char. Here a char 'carrage return' with ASCII value 13, will be converted to "~013".
  • Pass the processed string to method setData() to encode barcode
Note: The ASCII control characters (non-printing chars) will not be displayed in the barcode human readable text.


Code128 barcode = new Code128();
barcode.setProcessTilde(true);
String nonPrintChar = "~013";
barcode.setData("Code" + nonPrintChar + "128");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-ascii-non-printing.png");





How to create 2d barcode with Unicode text encoded in Java application?

Top
The ISO/IEC 8859-1 standard character set is used in various barcode types, as it covers a wide range of characters in English, French, Italian, Spanish, etc. However, if you want to encode data from other character sets, such as Arabic, Chinese, Japenese and Greek, you can simply convert the special char to Unicode encoding first, and then encode it in QR Code, Data Matrix or PDF-417.

Below is the Java demo code for 2D barcodes generation & encryption, in which UTF-8 encoding is applied to convert the original data to Unicode. Please note that the decoded data need to be converted back so you can get your original data for the barcode image.

  • Enable Unicode text encoding using method setEncodeUnicodeText(true)s
  • Input the Unicode text string in method setData(), and print the 2d barcode to an image file
QRCode barcode = new QRCode();
barcode.setEncodeUnicodeText(true);
barcode.setData("你好");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-unicode-text.png");





How to create 2d barcode with binary data in Java application?

Top
Most of the 2d barcodes support binary data mode. You can encode and create a 2d barcode (QR Code, Data Matrix, PDF417) from binary data, such as image, audio, or video data file.

Using OnBarcode Java Barcode Generator library, you will quickly generate 2d barcode from a binary data in Java web or desktop application.

  • Set the 2d Data Matrix encoding data mode as BASE256 in setDataMode(DataMatrix.M_BASE256). The Data Matrix Base 256 encoding mode shall be used to encode any 8-bit byte data.
  • Enable process tilde setProcessTilde(true) to handle binary data
  • Convert each byte value to a three-digit string, and add '~' in the beginning of the each char
  • Pass the processed string to method setData() to encode and print 2d barcode
String message = "你好";
byte[] bytes = message.getBytes("UTF-8");
StringBuilder dataInBytes = new StringBuilder();
for (int i=0; i<bytes.length; i++)
{
	int unsignedByte = bytes[i] & 0xFF;
	dataInBytes.append("~" + String.format("%03d", unsignedByte));
}

DataMatrix barcode = new DataMatrix();
barcode.setDataMode(DataMatrix.M_BASE256);
barcode.setProcessTilde(true);
barcode.setData(dataInBytes.toString());
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-binary.png");





How to Encode GS1 Barcodes in Java Class?

Top
This Java Barcode Library can encode UPC/EAN Barcodes with GS1 standard pre-configured. Alternatively, if you want to encode GS1-compatible QR Code, Data Matrix, GS1-Databar, GS1-128/EAN-128 or ITF-14, please follow the basic Java class sample code here.

Please note that the checksum character is automatically calculated and added to some linear barcode with obligatory check digit requirement. If you want to reduce barcode size, change barcode value, customize image color / orientation, or switch to another output method, simple add more in the Java barcode syntax below.

The following Java source code will generate a GS1-128 barcode using Java Barcode Generator library.
EAN128 barcode = new EAN128();
barcode.setData("(00)395123451234567895(01)09501101530003");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-gs1.png");





How to encode EAN/UPC add-on code using Java Barcode library?

Top
The EAN/UPC barcodes (EAN-13, EAN-8, UPC-A, UPC-E, ISBN, ISSN) supports 2-digit or 5-digit add-on code encoding.


EAN-13 with 2 digits add-on code

The following Java source code will generate an EAN-13 barcode with 2 digits add-on code using Java Barcode Generator library.
  • Set add-on code using method setSupData()
EAN13 barcode = new EAN13();
barcode.setData("123456789012");
barcode.setSupData("01");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-ean-upc-addon-2.png");



UPC-A with 5 digits add-on code

The following Java source code will generate a UPC-A barcode with 5 digits add-on code using Java Barcode Generator library.
  • Set add-on code using method setSupData()
UPCA barcode = new UPCA();
barcode.setData("12345678901");
barcode.setSupData("12345");
barcode.drawBarcode("c://Output//OnBarcode.com//java-barcode-data-ean-upc-addon-5.png");





Java Barcode Generation Guide for Linear & 2D Barcode Types

Top




































Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.