Java Code 128 Generator Tutorial
Generate, create barcode Code 128 images in Java applications (Servlet, Class, Jasper Report)
Download Java Barcode Generator Free Evaluation
Purchase Java Barcode Generator SDK License
This Java Barcode Generator proves very helpful for our project. Thanks a lot!
- Charly Nelson

Generate, Create, Print, Draw Code 128 barcode in Java projects

  • Easy to Generate Code 128 in Java class, Java Bean, Applet, Swing applications
  • Create Code 128 linear barcode in Java Servlet, EJB, JSP, Tomcat, JBoss server side applications
  • Print, draw Code 128 barcode images in Eclipse BIRT, iReport, Jasper Reports Java reporting software
  • Generating & encoding industry standard Code 128 Bar Code images in EPS, PNG, GIF, JPEG formats
  • Compatible with latest ISO / IEC 15417 (2nd edition 2007-05-15)
  • Completely written and created in Java. Support JDK 1.4.2 and later version
  • Simple to redistribute Java Code 128 barcode library SDK. No registration key or activation code required.
  • Reliable Java library component for Code-128 generation





Java Barcode Code 128 Generator Introduction
Top
Java Barcode is a Java barcode generator Java library, which generates and prints standard Code 128 and 20+ linear and 2d barcodes in Java applications.

In free evaluation version of Java Barcode library, you will find compiled Java barcode library (single Jar file) to create, print Code 128 and other linear, 2d barcodes in your Java projects, detailed tutorial for generation barcodes in Java, and complete sample Java source code to generate Code 128 in Java class. Downloaded Java barcode generation software allows you to create and print QR Code, Data Matrix, UPC, GS1-128, Code 93, PDF417, Code 39, Intelligent Mail, and other barcodes in your Java products.

Barcode Code-128 Introduction

Code 128 is a very high-density barcode symbology. (A special application of Code 128 named GS1-128 is used extensively world wide in shipping and packaging industries.) It is used for alphanumeric or numeric-only barcodes.

Java Code 128 Generator - Valid Data Scope

Java Code 128 Generator encodes:
  • All 128 characters of ASCII
  • Values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.
How to Generate Code 128 in Java Class?
Top
Below is some Java demo code for generating Code 128 linear barcodes in Java Class. You can simply copy it to your barcoding project for a test. For more Code 128 settings, view here: Java Code 128 Generator Demo Source Code
// Create Java Code128 object 
Code128 barcode = new Code128();

// Set Code128 data text to encode
barcode.setData("CODE128-IN-JAVA");

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

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

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

// Generate Code128 barcode & encode into EPS
barcode.drawBarcode2EPS("C://barcode-code128.eps");
How to Create Code 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=0123456789&TYPE=CODE128
  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=0123456789&TYPE=CODE128"/>
How to Generate Code 128 Image in Java Servlet Class?
Top
import com.onbarcode.barcode.AbstractBarcode; 
import com.onbarcode.barcode.Code128;
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 {
Code128 barcode = new Code128();
barcode.setData("0123456789");

ServletOutputStream servletoutputstream = response.getOutputStream();

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

// Generate Code-128 barcode & output to ServletOutputStream
barcode.drawBarcode(servletoutputstream);

} catch (Exception e) {
throw new ServletException(e);
}
}
}
How to Generate & Print Barcode Code 128 Image in Jasper Reports?
Top
Code 128 barcode generation in Jasper Reports is also supported by this Java barcode generator. Here is a Complete Guide for Barcode Generation in Jasper Reports.
How to Generate & Print Barcode Code 128 Image in iReport?
Top
To create, embed Code 128 barcodes in iReport, here is the Complete Guide for Barcode Generation in iReport.
How to Generate & Print Barcode Code 128 Image in Eclipse BIRT?
Top
How to Set Generated Barcode Code 128 Image Width and Height?
Top
  1. You can set barcode image width and height through properties barcodeWidth and barcodeHeight values.
  2. You can set X (bar module width) and Y (bar module height) values
Java Code 128 Generator - Barcode Property Settings
Top
Java Code 128 Generator in Java Class: com.onbarcode.barcode.Code128

Category Properties Value Comments
Basic Property: data
URL: DATA
Type: String
Default: ""
Code 128 barcode data to encode

Code 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 for Code 128.
 
Code 128
Special
Property: codeSet
iReport & URL: CODE-SET
Type: int
Default: 0 (SET_AUTO)
4 valid code sets: 0 (SET_AUTO), 1 (SET_A), 2 (SET_B), 3 (SET_C)
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, such as non-printable chars in ASCII table.

  • 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
 
Barcode
Size
Related
Property: autoResize
iReport & URL: AUTO-RESIZE
Type: boolean
Default: false
Auto resize the generated Code 128 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 Java Barcode library.
Valid values: 0: pixel; 1: inch; 2: cm.
Property: X
iReport & URL: X
Type: float
Default: 1
Width of Code 128 bar module (narrow bar), default is 1 pixel
Property: Y
iReport & URL: Y
Type: float
Default: 30
Height of Code 128 bar module, default is 30 pixel
Property: barcodeWidth
iReport & URL: BARCODE-WIDTH
Type: float
Default: 0
Generated Code 128 barcode image width.

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

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

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
Code 128 image background color
Property: foreColor
iReport & URL: FORE-COLOR
Type: Color
Default: black
Code 128 image foreground color
 
Font
Style
Property: showText
iReport & URL: SHOW-TEXT
Type: boolean
Default: true
If true, printing Code 128 encoding data below the barcode, otherwise do not print.
Property: textFont
iReport & URL: TEXT-FONT
Type: Font
Default:
new Font("Arial", Font.PLAIN, 11)
Code 128 text (printed below barcode) font style.

In Java Servlet web streaming, using the url paramter in the following format:
&TEXT-FONT=Arial|plain|11
Property: textMargin
iReport & URL: TEXT-MARGIN
Type: float
Default: 6
Space between barcode and printed barcode data, default is 6 pixel
Property: textColor
iReport & URL: TEXT-COLOR
Type: Color
Default: black
Barcode text (printed below barcode) 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.