Barcode Generation in Java Class
How to create linear, 2D barcode images in Java Class Library Application
Download Java Barcode Generator Free Evaluation
Purchase Java Barcode Generator SDK License
We found the Java Barcode an easy barcode solution for JasperReports.
- Gary Lipkowitz, USA

Creating, printing high-quality barcode images using Java sample code

  • Mature Java Barcode library tool with Headless Java support
  • Supporting JDK 1.4.2 and later versions
  • More than 30 barcode types (QR Code included) combined into single jar file
  • Java sample code provided to create valide barcode images in Java Class
  • Add barcode functionality into Jasper Report, iReport, Oracle Report & Eclipse BIRT with Java core
  • Easy interface to print barcode using Java code programming and adjust size, resolution, rotation, etc
  • Simple to generate best Java bar code labels in Jpeg, Gif, Png image formats
  • Check character automatically calculated for those linear barcodes required
  • Professional Java barcode SDK with outstanding barcode output
This page is a tutorial to create postal and other linear, two-dimensional barcodes in Java Class using advanced OnBarcode Java Barcode Generator Library. Java sample codes are provided as how to generate barcodes, adjust barcode size, and customize barcode image formats using Java coding. Developers can store barcode image to database for later use. For Java server-side or client-side applications, please navigate to corresponding guide page.
OnBarcode also provides other Java barcode example tutorials:
  1. Java Barcode Generator Tutorial - How to generate & draw multiple barcode images in Java applications
  2. Java Servlet Barcoder Tutorial - How to stream & display barcodes in Java web applications (JSP Servlet / html pages)
  3. iReport Barcode Tutorial - How to print & embed barcode pictures in iReport with Java Barcode Plugin
How to Install Java Barcode Library
Top
  1. Open your IntelliJ IDEA and create a new project
  2. Add a Directory named "lib" in the Java project built step ahead
  3. Download the free java barcode trial, unzip the package and copy the barcode.jar file into the lib file
  4. In Modules settings, add the barcode.jar file to classpath
  5. Create a new class and copy the following Java sample code to your program for barcode generation & implementation
How to Create Barcodes in Java Class Library
Top
This Java Barcode Generator supports printing over 30 barcode types. In the following part, we will take Code 39 as example to show Java barcode generation, image format setting, resolution, rotation and other output methods. You can view Java barcode generator api in the below demo. For embedding java barcode with number digit or alphanumeric string value, try other barcode symbols.
OnBarcode also provides specific guide to encode barcode data, or customize barcode image:
  1. Java Barcode Data Encoding Tutorial - How to create GS1-Compatible Barcodes or encode Unicode into Java Barcodes
  2. Java Barcode Image Setting Tutorial - How to generate barcodes in Java and adjust barcode image properties

Example to Adjust Barcode Dimension in Java Class


import com.onbarcode.barcode.Code39;

public class tutorial {
public static void main(String[] args)
{
try
{
Code39 barcode = new Code39();
barcode.setData("DATA");
barcode.setX(2);
barcode.setY(60);
barcode.setBarcodeWidth(150);
barcode.setBarcodeHeight(80);

barcode.setLeftMargin(0);
barcode.setRightMargin(0);
barcode.drawBarcode("C://java-code39.png");

}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Print Barcodes in Java Class in Png, Gif, Gif or EPS Image Formats


Code39 barcode = new Code39();
barcode.setData("DATA");

//Generate barcode in Gif image format
barcode.setImageFormat(0);
barcode.drawBarcode("C://barcode-code39.gif");

//Generate barcode in JPEG image format
barcode.setImageFormat(1);
barcode.drawBarcode("C://barcode-code39.jpg");

//Generate barcode in PNG image format
barcode.setImageFormat(2);
barcode.drawBarcode("C://barcode-code39.png");

//Generate barcode in EPS image format. The filename must ends with .eps
barcode.drawBarcode2EPS("C://barcode-Code39.eps");

More Barcode Settings in Java Class


//Set barcode image bar alignment property
barcode.setBarAlignment(1);

//Customize barcode image resolution
barcode.setResolution(96);

//Set barcode rotation rate. 0 degree(0), 90 degree(1), 180 degree(2), 270 degree(3)
barcode.setRotate(0);

//Customize barcode human-readable text
barcode.setShowText(true);
barcode.setTextFont(new Font("Arial", Font.BOLD, 11));
barcode.setTextMargin(8);

//Adjust barcode image color
barcode.setForeColor(Color.black);
barcode.setBackColor(Color.white);
barcode.setTextColor(Color.black);

barcode.drawBarcode("C://ob-code39.jpg");

More Barcode Generation Output 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

public byte[] drawBarcodeToBytes() throws Exception

public boolean drawBarcode(String imageFile) throws Exception

// Generate barcode on Graphics2D object within certain area
public void drawBarcode(Graphics2D g, Rectangle2D rectangle) throws Exception
Java Barcode Generation Guide for Linear & 2D Barcode Types
Top

Java Barcode Library SDK - Barcodes Generation

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, VB.NET Barcode Image, Java JSP Servlet. OnBarcode barcode products are supported by RasterEdge high quality .NET Imaging SDK, Java Imaging Library, and their easy and simple documents, like imaging in C#, imaging in VB.NET, PDF in C# and PDF in VB.NET.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.