1. Barcode Introduction
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).
CH(100)12345777AI(21)12345678.gif)
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'.
2. 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.
3. How to Generate Barcode Image in Standalone Java Applications?
The following code illustrates how to create a barcode in a Java class
1 Linear linear = new Linear();
2 linear.setData("123456789");
3 linear.setType(Linear.EAN128);
4 linear.renderBarcode("c:/barcode.gif");
- Create a Linear object (line 1)
- set Linear object properties (line 2 - 3)
- save into gif file (line 4)
4. How to Generate Barcode Image in Web Applications?
There are two ways to create barcode images in your Java web applications.
-
This is the simplest way to stream barcode image using our provided barcode servlet classes.
And it will not save barcode images in your server side.
- Under demo package, copy barcode folder to your java servlet container like tomcat.
- To test your installation, goto http://YourDomain:Port/barcode/linear?Data=123456789&Type=EAN128
- To create barcode image in your JSP or html page, you can pass the url to IMG tag src value.
For example, <img src="http://YourDomain:Port/barcode/linear?Data=123456789&Type=EAN128" />
-
The second method is similar with the way to generate barcode in Java applications.
5. How to Generate Barcode Image in JasperReports?
The following jasper xml content illustrates how to insert a barcode into JasperReports
<import value="com.barcodelib.barcode.BarcodeJasperFactory"/>
Import class BarcodeJasperFactory to report.
<image scaleImage="Clip" hAlign="Center">
<reportElement x="50" y="110" width="515" height="120"/>
<graphicElement/>
<imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[new com.barcodelib.barcode.BarcodeJasperRenderer(BarcodeJasperFactory.createLinear(26, "123456789"))]]></imageExpression>
</image>
Please go to class BarcodeJasperFactory in Java doc for all methods to create linear barcode.
Developers can also extend or modify BarcodeJasperFactory class to meet their own requirements. Complete BarcodeJasperFactory.java Source Code
6. How to Generate Barcode Image in Eclipse BIRT?
Our Java barcode library supports generating barcode image in Eclipse BIRT framework.
Click here to view the details.
7. How to Save Barcode Image?
Just call Linear object method renderBarcode, e.g. linear.renderBarcode("c:/barcode.gif");
8. Barcode Property Settings
-
Set the type property to Linear.EAN128.
Servlet Parameter: "Type".
-
Set the data property with the value to encode. Type is String.
Servlet Parameter: "Data".
-
Setting up barcode image size:
-
Set property uom (Unit of Measure) for properties barWidth, barHeight, 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 Parameter: "UOM".
-
Set the X (for barcode module width) and Y (for barcode module height) properties. Both types are float.
Servlet Parameter: "X", "Y".
-
Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float.
Servlet Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin".
-
Set the barcodeWidth (barcode image width) and barcodeHeight (barcode image height) properties. Both types are float.
Servlet Parameter: "BarcodeWidth", "BarcodeHeight".
-
Set the resolution property (Value is expressed in DPI - Dots per inch).
Servlet Parameter: "Resolution".
-
Setting up text style in barcode image:
-
Set the showText properties. If this value is true, barcode data will be displayed with the barcode.
Servlet Parameter: "ShowText".
-
Set the textFont property. The font used to display text in barcode image.
Servlet Parameter: "TextFont".
-
Set bearerBars property, if you want to draw borders around barcode image. Value can be Linear.BEARERBAR_UNSPECIFIED (-1. let library decide whether draw bear bars or not), Linear.BEARERBAR_NONE (0. no bear bars), Linear.BEARERBAR_FRAME (1. top, bottom, left, right borders drawn), Linear.BEARERBAR_TOPBOTTOM (2. only top, bottom's are drawn).
Servlet Parameter: "BearerBars".
-
Set rotate property, if you want to rotate barcode image.
Value can be
0 (Linear.ANGLE_0),
1 (Linear.ANGLE_90),
2 (Linear.ANGLE_180),
3 (Linear.ANGLE_270)
Servlet Parameter: "Rotate".
-
addCheckSum property is not applied. Barcode Library will automatically add a check sum in the end.
Servlet Parameter: "AddCheckSum".
-
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is false.
~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
Servlet Parameter: "ProcessTilde".
9. How to Set Generated Barcode Image Size?
To set barcode image width and height, there are two ways to do it.
1) You can set barcode image width and height through properties barcodeWidth and barcodeHeight values, barcode library will render the barcode image for you.
or
2) You can set X (barcode module width) and Y (barcode module height) values, barcode library will calculate the barcodeWidth and barcodeHeight values for you, and render the barcode image.
All Java Barcode Types/Symbologies