Java Code-128 Barcodes Generator for Java, Jasper Reports, BIRT
Code-128 is also known as ANSI/AIM
128, ANSI/AIM Code 128, USS Code 128, Uniform Symbology Specification Code 128,
Code 128 Code Set A, Code 128 Code Set B, Code 128 Code Set C, Code 128A, Code
128B, Code 128C
Code 128 is a very effective, high-density symbology which permits the encoding of alphanumeric data. The symbology includes a checksum digit for verification, and the bar code may also be verified character-by-character verifying the parity of each data byte. This symbology has been widely implemented in many applications where a relatively large amount of data must be encoded in a relatively small amount of space. It's specific structure also allows numeric data to be encoded at, effectively, double-density.
Code 128 Code Sets
Code Set A (or Chars Set A) includes all of the standard upper case U.S.
alphanumeric keyboard characters and punctuation characters together with the
control characters, (i.e. characters with ASCII values from 0 to 95 inclusive),
and seven special characters.
Code Set B (or Chars Set B) includes all of the standard upper case
alphanumeric keyboard characters and punctuation characters together with the
lower case alphabetic characters (i.e. characters with ASCII values from 32 to
127 inclusive), and seven special characters.
Code Set C (or Chars Set C) includes the set of 100 digit pairs from 00
to 99 inclusive, as well as three special characters. This allows numeric data
to be encoded as two data digits per symbol character, at effectively twice the
density of standard data.
Code 128 Special characters
The last seven characters of Code Sets A and B (character
values 96 - 102) and the last three characters of Code Set C (character values
100 - 102) are special non-data characters with no ASCII character equivalents,
which have particular significance to the bar code reading device.
Sample of a Code 128 Barcode
2. Java Code-128 Encoding Data Scope
Code 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 Code-128 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.CODE128);
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 Code-128 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=CODE128
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=CODE128" />
The second method is similar with the way to generate barcode in Java applications.
Create a barcode image in server side
1 Linear linear = new Linear();
2 linear.setData("123456789");
3 linear.setType(Linear.CODE128);
4 linear.renderBarcode("C:/Tools/Tomcat 5.5/webapps/YourWebApp/bimages/barcode.gif");
In your JSP page, you can using IMG tag to display generated image, like <img src="http://YourDomain:Port/YourWebApp/bimages/barcode.gif" />
5. How to Generate Barcode Code-128 Image in JasperReports?
The following jasper xml content illustrates how to insert a barcode into JasperReports
Just call Linear object method renderBarcode, e.g. linear.renderBarcode("c:/barcode.gif");
8. Java Code-128 Property Settings
Set the type property to Linear.CODE128, Linear.CODE128A, or Linear.CODE128B, or Linear.CODE128C.
Linear.CODE128 (default):Barcode Library will automatically switch between code sets
to encode the ASCII values.
Linear.CODE128A: Library will use the Char Set A which only
supports ASCII values from 0 to 95
Linear.CODE128B: Library will use the Char Set B which only
supports ASCII values from 32 to 127
Linear.CODE128C: Library will use the Char Set C which only
supports pairs of digits
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 here. Barcode Library will always add a check character between encoded data and stop character.
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 Code-128 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.