Barcode Generation in Java Class
How to create linear, 2D barcode images in Java Class Library Application
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:
- Java Barcode Generator Tutorial - How to generate & draw multiple barcode images in Java applications
- Java Servlet Barcoder Tutorial - How to stream & display barcodes in Java web applications (JSP Servlet / html pages)
- iReport Barcode Tutorial - How to print & embed barcode pictures in iReport with Java Barcode Plugin
How to Install Java Barcode Library
Top
- Open your IntelliJ IDEA and create a new project
- Add a Directory named "lib" in the Java project built step ahead
- Download the free java barcode trial, unzip the package and copy the barcode.jar file into the lib file
- In Modules settings, add the barcode.jar file to classpath
- 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:
- Java Barcode Data Encoding Tutorial - How to create GS1-Compatible Barcodes or encode Unicode into Java Barcodes
- 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