Java GS1-128 Generator Tutorial

Generate, create barcode EAN-128 images in Java applications (Class, Servlet, Jasper Report)

Download Java Barcode Generator Free Evaluation
Purchase Java Barcode Generator SDK License

Generate, Create, Print, Draw EAN-128 (GS1 128) barcode in Java projects

  • Easy to generate GS1-128/EAN-128 barcodes in Java Class, J2EE applications
  • Simple to redistribute Java GS1-128/EAN-128 barcode library. No registration key. No activation code
  • Generating high quality GS1-128/EAN-128 Bar Code images in GIF, JPEG, & EPS formats
  • Generate GS1-128/EAN-128 barcodes in Jasper Reports, iReport & Eclipse BIRT
  • Completely developed with Java source code
  • Mature GS1-128/EAN-128 barcode generation Java library used by 2000+ clients





Java Barcode GS1 128 / EAN 128 Generator Introduction
Top
Java Barcode is a Java barcode generator which generates high quality 1D (linear) and 2D (matrix) barcodes in Java, Jasper Reports, iReport, and Eclipse BIRT projects.

GS1 128 / EAN 128 Introduction

GS1-128 is an application standard of the GS1 implementation using the Code 128 barcode specification. The former correct name was UCC/EAN-128. Other no longer used names have included UCC-128 and EAN-128. GS1-128 uses a series of Application Identifiers to include additional data such as best before dates, batch numbers, quantities, weights and many other attributes needed by the user.

Java GS1 128 / EAN 128 Generator - Valid Data Scope

  • All 128 characters of ASCII
  • Values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.
Creating GS1-128 (UCC/EAN-128) Compliant BarCodes in Java
Top
OnBarcode Java Barcode Generator allows easily to add application identifiers in GS1 128 / EAN 128, by add parentheses to AIs.

For example, to encode AI (00), with data 350123451234567894, with second AI (21), with data 01234567, you need pass string "(00)350123451234567894(21)01234567" to barcode data property
EAN128 barcode = new EAN128(); 

barcode.setData("(00)350123451234567894(21)01234567");

ean128.drawBarcode("java-ean128.gif");
How to Generate EAN-128 / GS1-128 in Java Class?
Top
Here is some sample code for creating GS1-128 linear barcodes in Java class. If you need to adjust more barcode settings, please view here: Java GS1 128 Generator Demo Source Code
// Create Java EAN128 object 
EAN128 barcode = new EAN128();

// Set EAN128 data text to encode
barcode.setData("(00)350123451234567894");

// Generate EAN128 barcode & print into Graphics2D object
barcode.drawBarcode("Java Graphics2D object");

// Generate EAN128 barcode & encode into GIF format
barcode.drawBarcode("C://barcode-ean128.gif");

// Generate EAN128 barcode & encode into JPEG format
barcode.drawBarcode("C://barcode-ean128.jpg");

// Generate EAN128 barcode & encode into EPS
barcode.drawBarcode2EPS("C://barcode-ean128.eps");
How to Create & Encode GS1-128/EAN-128 image in HTML or JSP pages?
Top
  1. Under demo package, copy barcode folder and its contents to your tomcat.
  2. Start tomcat, navigate to http://YourDomain:Port/barcode/barcode?DATA=(00)350123451234567894&TYPE=EAN128
  3. To create bar code images in html or jsp pages, you can insert a image tag (img) into your page
  4. For example, <img src="http://YourDomain:Port/barcode/barcode?DATA=(00)350123451234567894&TYPE=EAN128"/>
How to Create & Print Barcode GS1-128/EAN-128 Image in Java Servlet Class?
Top
import com.onbarcode.barcode.AbstractBarcode; 
import com.onbarcode.barcode.EAN128;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;

public class BarcodeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try {
EAN128 barcode = new EAN128();
barcode.setData("(00)350123451234567894");

ServletOutputStream servletoutputstream = response.getOutputStream();

response.setContentType("image/jpeg");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);

// Generate EAN128 barcode & output to ServletOutputStream
barcode.drawBarcode(servletoutputstream);

} catch (Exception e) {
throw new ServletException(e);
}
}
}
How to Generate GS1-128/EAN-128 Barcode Image in Jasper Reports?
Top
With this Java Barcode generator, you can also generate high-quality GS1-128 barcode images in Jasper Report. Here is the tutorial: Complete Guide for Barcode Generation in Jasper Reports
How to Generate GS1-128/EAN-128 Barcode Image in iReport?
Top
This Java Barcode Generator is powerful enough to support creating bulk GS1-128 barcode images in iReport, either though JRRenderable implementation or buildin servlet application. To learn more, here is the guide for you: Complete Guide for Barcode Generation in iReport
How to Generate GS1-128/EAN-128 Barcode Image in Eclipse BIRT?
Top
How to Set Generated GS1-128/EAN-128 Barcode Image Width and Height?
Top
  1. You can set barcode image width and height through properties barcodeWidth and barcodeHeight values.
  2. Or you can set X (bar module width) and Y (bar module height) values
Java EAN 128/GS1 128 Generator - Property Settings
Top
Java EAN 128/GS1 128 Generator in Java Class: com.onbarcode.barcode.EAN128

Category Properties Value Comments
Basic Property: data
URL: DATA
Type: String
Default: ""
Barcode value to encode

GS1-128/EAN-128 Valid Data Char Set:
  • all 128 ASCII characters (Char from 0 to 127)

Property: addCheckSum
iReport & URL: ADD-CHECK-SUM
Type: boolean
Default: false
addCheckSum property is not applied here.
 
GS1 128
EAN 128
Special
Property: processTilde
iReport & URL: PROCESS-TILDE
Type: boolean
Default: false
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data.

  • 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255); ASCII character '~' is presented by ~126
    Strings from "~256" to "~299" are unused
  • 2-byte character (Unicode): ~6ddddd (character value from 00000 ~ 65535)
    Strings from "~665536" to "~699999" are unused
  • for GS1 AI Code:
    ~ai2: AI code with 2 digits
    ~ai3: AI code with 3 digits
    ~ai4: AI code with 4 digits
    ~ai5: AI code with 5 digits
    ~ai6: AI code with 6 digits
    ~ai7: AI code with 7 digits
 
Barcode
Size
Related
Property: autoResize
iReport & URL: AUTO-RESIZE
Type: boolean
Default: false
Auto resize the generated barcode image
Property: barAlignment
iReport & URL: BAR-ALIGNMENT
Type: int
Default: 1 (center)
Barcode horizontal alignment inside the image. 0: left, 1: center, 2: right.
Property: uom
iReport & URL: UOM
Type: int
Default: 0 (pixel)
Unit of meature for all size related settings in the library.
Valid values: 0: pixel; 1: inch; 2: cm.
Property: X
iReport & URL: X
Type: float
Default: 1
Width of barcode bar module (narrow bar), default is 1 pixel
Property: Y
iReport & URL: Y
Type: float
Default: 30
Height of barcode bar module, default is 30 pixel
Property: barcodeWidth
iReport & URL: BARCODE-WIDTH
Type: float
Default: 0
Barcode image width.

If barcodeWidth setting is smaller than the barcode required minimum width, the library will automatically reset to barcode minimum width.
Property: barcodeHeight
iReport & URL: BARCODE-HEIGHT
Type: float
Default: 0
Barcode image height.

If barcodeHeight setting is smaller than the barcode required minimum height, the library will automatically reset to barcode minimum height.
Property: leftMargin
iReport & URL: LEFT-MARGIN
Type: float
Default: 0
Barcode image left margin size.
Property: rightMargin
iReport & URL: RIGHT-MARGIN
Type: float
Default: 0
Barcode image right margin size.
Property: topMargin
iReport & URL: TOP-MARGIN
Type: float
Default: 0
Barcode image top margin size.
Property: bottomMargin
iReport & URL: BOTTOM-MARGIN
Type: float
Default: 0
Barcode image bottom margin size.
Property: resolution
iReport & URL: RESOLUTION
Type: int
Default: 72
Barcode image resolution in DPI (Dots per inch).
Property: rotate
iReport & URL: ROTATE
Type: int
Default: 0 (IBarcode.ROTATE_0)
Valid values:

  • 0 (IBarcode.ROTATE_0)
  • 1 (IBarcode.ROTATE_90)
  • 2 (IBarcode.ROTATE_180)
  • 3 (IBarcode.ROTATE_270)
 
Barcode
Colors
Property: backColor
iReport & URL: BACK-COLOR
Type: Color
Default: white
Barcode image background color
Property: foreColor
iReport & URL: FORE-COLOR
Type: Color
Default: black
Barcode image foreground color
 
Font
Style
Property: showText
iReport & URL: SHOW-TEXT
Type: boolean
Default: true
If true, display barcode data text under the barcode, otherwise do not display.
Property: textFont
iReport & URL: TEXT-FONT
Type: Font
Default:
new Font("Arial", Font.PLAIN, 11)
Barcode text font style.

In Java Servlet web streaming, using the url paramter in the following format:
&TEXT-FONT=Arial|bold|9
Property: textMargin
iReport & URL: TEXT-MARGIN
Type: float
Default: 6
Space between barcode and barcode data text, default is 6 pixel
Property: textColor
iReport & URL: TEXT-COLOR
Type: Color
Default: black
Barcode text color
 
Methods
// generate barcode and output to OutputStream object
public boolean drawBarcode(OutputStream outputStream) throws Exception

// generate barcode into a new BufferedImage object
public BufferedImage drawBarcode() throws Exception

/*
    Use this method to generate barcode, and save into gif or jpeg files
    1. to save into gif file, filename ends with ".gif", like "c:\\barcode.gif"
    2. to save into jpeg file, filename ends with ".jpg", like "c:\\barcode.jpg"
    3. to save into png file, filename ends with ".png", like "c:\\barcode.png"
*/
public byte[] drawBarcodeToBytes() throws Exception

public boolean drawBarcode(String imageFile) throws Exception

// Generate barcode and save into EPS file, the filename must ends with ".eps"
public void drawBarcode2EPS(String filename) throws Exception

// Generate barcode on Graphics2D object within certain area
public void drawBarcode(Graphics2D g, Rectangle2D rectangle) throws Exception
Java Barcode Generator Supporting Barcode Symbology Types
Top
Barcode for Java - Bar Code Types Geneation
OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.