Our Customers
Contact Us Email: support@barcodelib.com
Home > Java Barcode Generator > Java Barcode Generation Guide > Java GS1-128 (UCC/EAN-128) Barcode Generator
Download Barcode for Java Trial

Java GS1-128 (UCC/EAN-128) Barcodes Generator Guide

GS1-128 (UCC/EAN-128) Bar Code Generation Guide in Java class, J2EE, Jasper Reports, iReport & Eclipse BIRT
  • Comprehensive barcoding toolkit for Java with advanced GS1-128/EAN-128 generation functions
  • 100% build in Java, compatible with JDK 1.4 and later version
  • Easily generate GS1-128/EAN-128 barcodes in Java applications with virtual machine
  • Generate high-readability GS1-128/EAN-128 barcodes in JPEG, GIF & PNG image formats
  • Generate GS1-128/EAN-128 barcode in Jasper Reports & iReport
  • Generate GS1-128/EAN-128 barcode in Eclipse BIRT
  • Professional Java Barcode Generator library since 2003
  • Four types of royalty-free developer license with lifelong to use
GS1-128/EAN-128 Barcode Introduction
GS1-128 / EAN-128 is also known as EAN-128, UCC-128, USS-128, GS1-128, UCC.EAN-128, GTIN-128, UCC-12, EAN/UCC-13, EAN/UCC-14.
The UCC/EAN-128 Symbology is a subset of the more general Code 128 Symbology. UCC/EAN-128 was developed to provide a worldwide format and standard for exchanging common data between companies. While other bar codes simply encode data with no respect for what the data represents, UCC/EAN-128 encodes data and encodes what that data represents.
UCC/EAN-128 has a list of Application Identifiers (AI). The Application Identifier is a 2, 3, or 4-digit number that identifies the type of data which follows. By convention, the Application Identifier is enclosed in parentheses when printed below the barcode (the parentheses are only for visual clarity, and are not encoded in the barcode).

Sample of a UCC/EAN-128 Barcode

How to encode UCC/EAN-128 values using Barcode Library

Introduction
UCC/EAN 128 encodes the so called Element Strings which are composed of an Application Identifier (AI) plus a data field. Each AI identifies the meaning and format of the data following it. Note that the AI has parentheses around it in the human readable text, but the parentheses are not encoded in the barcode.
Encode AI Code
In Barcode Library, developer mush put (dddd) around AI code, for the above sample image, you must set data property = '(21)d12345777(21)12345678'.
GS1-128/EAN-128 Encoding Data Scope
UCC/EAN 128 Barcode for Java supports:
  • all 128 characters of ASCII
  • values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.
How to Generate GS1-128/EAN-128 Barcode in Java Class?
The following Java code illustrates how to create a GS1-128/EAN-128 barcode, and output to various formats.
1     Linear linear = new Linear(); 
2 linear.setType(Linear.EAN128);
3 linear.setData("(21)d12345777(21)12345678");
4 linear.renderBarcode("c:/barcode.gif");

5 BufferedImage bufferedImage = linear.renderBarcode();

6 byte[] barcodeBytes = linear.renderBarcodeToBytes();

7 Graphics2D g = ...
8 Rectangle2D rectangle = ...
9 linear.renderBarcode(g, rectangle);

10 OutputStream outputStream = ...
11 linear.renderBarcode(outputStream);
  • Create a Linear barcode object (line 1)
  • Set Linear object barcode type to GS1-128/EAN-128 (line 2)
  • Set GS1-128/EAN-128 barcode data to encode (line 3)
  • Encode generated GS1-128/EAN-128 barcode into gif image file (line 4)
  • Generate GS1-128/EAN-128 and output to BufferedImage object (line 5)
  • Generate GS1-128/EAN-128 in bitmap and output to byte[] (line 6)
  • Generate GS1-128/EAN-128 and draw to defined area (Rectangle2D) on Graphics2D (line 7-9)
  • Generate GS1-128/EAN-128 and output to OutputStream (line 10-11)
How to Generate GS1-128/EAN-128 Barcode Image in Java Web Applications?
There are two methods to create GS1-128/EAN-128 barcode images in your Java web applications.
  1. The simplest way is to stream barcode image using our buildin barcode servlet application.
    1. Download the Barcode for Java Trial Package, and unzip it.
    2. Under java_barcode_trial package, copy barcode folder to your java servlet container like tomcat.
    3. Restart tomcat. Now you have installed successfully.
    4. To test your installation, open your web browser and navigate to:
      http://YourDomain:Port/barcode/linear?Data=123456789&Type=EAN128
    5. To create barcode image in your JSP or html page, you need pass the url to IMG tag src value. For example,
      <img src="http://YourDomain:Port/barcode/linear?Data=123456789&Type=EAN128" />
      Using this method, it will not generate any barcode images in your server side.
  2. The second method is to generate barcode images in your server side.
    • Create a barcode image in server side, like
      Linear linear = new Linear();
      linear.setData("123456789");
      linear.setType(Linear.EAN128);
      linear.renderBarcode("C:/Tools/Tomcat 5.5/webapps/YourWebApp/barcode-images/barcode.gif");
    • In your JSP or HTML page, you need use IMG tag to display generated image, like
      <img src="http://YourDomain:Port/YourWebApp/barcode-images/barcode.gif" />
How to Generate Barcode GS1-128/EAN-128 Image in Jasper Reports, iReport, Eclipse BIRT?
Java GS1-128/EAN-128 Barcode Property Settings
  1. Set the type property to Linear.EAN128.
    Servlet URL Parameter: "Type". Value: 26. Sample: &Type=26
  2. Set the data property with the value to encode.
    Type is String.
    Servlet URL Parameter: Data. Sample: &Data=(21)d12345777(21)12345678
    • Valid Data Scope:
      • all 128 characters of ASCII
    • Valid Data Format:Valid Codabar data includes the above chars only, do not include Codabar Start and Stop chars ("A", "B", "C", and "D") in this property.
    • Sample: "(21)d12345777(21)12345678".
    • About AI (Application Identifiers)
      • In Barcode Library, you can use (dddd) format to encode AI code "dddd".
        For example, to encode AI code 21 with value d12345777,and AI code 21 with value 12345678.
        barcode.setData("AI(21)d12345777AI(21)12345678").
    • About ASCII Data Encoding
      • In Barcode Library, you can use tilde ~ format to encode any ASCII data (from ASCII value 0 to 127).
        For example, ASCII 100 is char 'd'. ~100 = d.So for the above sample EAN-128 data, you can need first set processTilde to true,set data property = "(21)~10012345777(21)12345678".

        Sample Code:
        barcode.setProcessTilde(true);
        barcode.setData("(21)~10012345777(21)12345678");
  3. addCheckSum property is not applied.
  4. Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the encoding data. Default is false.
    Servlet Parameter: "ProcessTilde". Values: "t" (true), "f" (false). Sample: &ProcessTilde=t
    Format of the tilde:
    • ~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
  5. Barcode image size settings.
    • Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin.
      Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2).
      Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0.
    • Set the X (for barcode module width) and Y (for barcode module height) properties.
      Both types are float. Default X is 3. Y is 75.
      Servlet URL Parameter: "X", "Y". Sample: &X=3&Y=75.
    • Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float.
      Default values are 0 for all 4 margin settings.
      Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0.
    • Set the resolution property (Value is expressed in DPI - Dots per inch).
      Default is 72 dpi.
      Servlet URL Parameter: "Resolution". Sample: &Resolution=72.
  6. Setting up text style in barcode image.
    • Set the showText properties. If this value is true, barcode data will be displayed with the barcode.
      Default is true.
      Servlet URL Parameter: "ShowText". Value: "t" (true), "f" (false). Sample: &ShowText=t.
    • Set the textFont property. The font used to display text in barcode image.
      Default is new Font("Arial", Font.PLAIN, 11).
      Servlet URL Parameter: "TextFont". Value format: [font name]|[font style]|[font size]. Sample Values: &TextFont=Arial|Bold|12
  7. With rotate property, you can display barcode horizontally or vertically.
    Default value is 0.
    Servlet URL Parameter: "Rotate". Sample: &Rotate=0.
    • 0 (Linear.ANGLE_0),
    • 1 (Linear.ANGLE_90),
    • 2 (Linear.ANGLE_180),
    • 3 (Linear.ANGLE_270).
How to Set Generated GS1-128/EAN-128 Barcode Image Size?

All Java Barcode Types/Symbologies

Encode Linear Barcodes:
Encode Matrix Barcodes: