Our Customers
Contact Us Email: support@barcodelib.com
Home > Barcode for Java > Java Barcode Generation Guide - How to use Java Barcode Generator Library to generate linear & 2d barcode images
Download Barcode for Java Trial

Java Barcode Generation Guide

How to Generate and Draw 1D & 2D Barcode Images for Java Applications
Generating linear & 2D barcode images using Barcode for Java library, is a simply and easy task.
This page is a demonstration and tutorial on how to generate barcode images using Java Barcode Generator library in your Java programs. Please download free Java Barcode Library trial first to get started.
Barcode for Java Trial Package Overview
Barcode for Java is a mature & reliable Java barcode generator library for linear & 2d barcode generation in J2SE, J2EE, and Java reporting framework applications (Jasper Reports, iReport and Eclipse BIRT).
Barcode for Java trial package includes:
  • barcode.jar, Java classes includes all supporting barcode types and functions
  • /demo-src, Contains demo Java souce code for barcode generation
  • /javadoc, Java docs
  • /Developer-Guide.html, Guide for developers to use this Java bar coding library
  • /barcode, Contains Barcode for Java Buildin Barcode Generation web application for developers. See how to
  • LicenseAgreement.txt, Barcode for Java End-User License Agreement
Install Barcode for Java Library
  1. Install Barcode for Java Library to your Java Projects
    • Copy barcode.jar file to your Java project library folder, and add barcode.jar to your project reference
  2. Install Barcode for Java Library to your Java web applications
  3. Install Barcode for Java Library to your Java reporting programs
How to Generate Barcodes in Java Class?

Install

Copy barcode.jar file to your Java application library folder, and add barcode.jar to your project reference.

Implement

The following Java code illustrates how to generate a 1d (linear) barcode, Code 128, using Java class:
1     Linear linear = new Linear(); 
2 linear.setData("123456789");
3 linear.setType(Linear.CODE128);
4 linear.renderBarcode("c:/barcode.gif");

5 BufferedImage bufferedImage = linear.renderBarcode();

6 byte[] barcodeBytes = linear.renderBarcodeToBytes();

7 Graphics2D g = ...
8 Rectangle2D rectangle = ...
9 linear.renderBarcode(g, rectangle);

10 OutputStream outputStream = ...
11 linear.renderBarcode(outputStream);
  • Create a linear barcode object (line 1)
  • Set linear object barcode properties (line 2 - 3)
  • Generate Code 128 barcode and encode into gif image file format (line 4)
  • Generate barcode and output to BufferedImage object (line 5)
  • Generate barcode in bitmap and output to byte[] (line 6)
  • Generate barcode and draw to defined area (Rectangle2D) on Graphics2D (line 7-9)
  • Generate barcode and output to OutputStream (line 10-11)
How to generate Data Matrix barcode image in Java class:
1     DataMatrix barcode = new DataMatrix(); 
2 barcode.setData("DATA MATRIX");
// add more Data Matrix property settings here

3 barcode.renderBarcode("c:/barcode.gif");

4 BufferedImage bufferedImage = barcode.renderBarcode();

5 byte[] barcodeBytes = barcode.renderBarcodeToBytes();

6 Graphics2D g = ...
7 Rectangle2D rectangle = ...
8 barcode.renderBarcode(g, rectangle);

9 OutputStream outputStream = ...
10 barcode.renderBarcode(outputStream);
  • Create a Data Matrix barcode image object (line 1)
  • Set Data Matrix object barcode properties (line 2)
  • Generate Data Matrix barcode and encode into gif image file format (line 3)
  • Generate Data Matrix and output to BufferedImage object (line 4)
  • Generate Data Matrix in bitmap and output to byte[] (line 5)
  • Generate Data Matrix and draw to defined area (Rectangle2D) on Graphics2D (line 6-8)
  • Generate Data Matrix and output to OutputStream (line 9-10)
How to generate PDF-417 barcode images in Java class:
1     PDF417 barcode = new PDF417(); 
2 barcode.setData("PDF 417");
// add more PDF417 property settings here

3 barcode.renderBarcode("c:/barcode.gif");

4 BufferedImage bufferedImage = barcode.renderBarcode();

5 byte[] barcodeBytes = barcode.renderBarcodeToBytes();

6 Graphics2D g = ...
7 Rectangle2D rectangle = ...
8 barcode.renderBarcode(g, rectangle);

9 OutputStream outputStream = ...
10 barcode.renderBarcode(outputStream);
  • Create a PDF417 barcode object (line 1)
  • Set PDF417 object barcode properties (line 2)
  • Generate PDF-417 barcode and encode into gif image format (line 3)
  • Generate PDF-417 and output to BufferedImage object (line 4)
  • Generate PDF-417 in bitmap and output to byte[] (line 5)
  • Generate PDF-417 and draw to defined area (Rectangle2D) on Graphics2D (line 6-8)
  • Generate PDF-417 and output to OutputStream (line 9-10)
How to generate QR-Code barcode images in Java class:
1     QRCode barcode = new QRCode(); 
2 barcode.setData("123456789");
// add more QRCode property settings here

3 barcode.renderBarcode("c:/barcode.gif");

4 BufferedImage bufferedImage = barcode.renderBarcode();

5 byte[] barcodeBytes = barcode.renderBarcodeToBytes();

6 Graphics2D g = ...
7 Rectangle2D rectangle = ...
8 barcode.renderBarcode(g, rectangle);

9 OutputStream outputStream = ...
10 barcode.renderBarcode(outputStream);
  • Create a QR-Code barcode object (line 1)
  • Set QR-Code object barcode image properties (line 2)
  • Generate QR-Code barcode and encode into gif image format (line 3)
  • Generate QR-Code and output to BufferedImage object (line 4)
  • Generate QR-Code in bitmap and output to byte[] (line 5)
  • Generate QR-Code and draw to defined area (Rectangle2D) on Graphics2D (line 6-8)
  • Generate QR-Code and output to OutputStream (line 9-10)
How to Generate Barcode Image in Web Applications?
There are two ways to create barcode images in your Java web applications.
  1. The simplest way - How to generate barcode image is to use our Build-in Barcode Generation web application (The application is included in Barcode for Java trial package. download it).
    And it will not save generated barcode images in your server side. Follow the steps to see how:
    • Copy folder barcode, under BarcodeLib_JavaBarcode_Trial (or BarcodeLib_JavaBarcode_Production), to your java servlet container like Tomcat.
    • Restart Tomcat, and test your installation, open web browser and navigate to:
      http://YourDomain:Port/barcode/linear?Data=123456789&Type=CODE128
    • To create & insert barcode images in your JSP or html pages, you can pass the url to IMG tag src value. For example,
      <img src="http://YourDomain:Port/barcode/linear?Data=123456789&Type=CODE128" />
  2. The second method - Similar with the way to generate barcode in Java class.
    • Create a barcode & save the barcode image to your server side:
      Linear linear = new Linear();
      linear.setData("123456789");
      linear.setType(Linear.CODE128);
      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" />
How to Generate Barcode Images in JasperReports, iReport & Eclipse BIRT Programs?

Barcode for Java Each Barcode Symbology Property Settings

Java 1D/Linear Barcodes:
Java 2D/Matrix Barcodes:
Java Barcode Generator Technical Support
If you have any questions or requests, please send email to support@barcodelib.com.





Provides High Quality Java Barcode Generator, Barcode Generator Java, Java Bar Code Generator Library, Java Barcode Generator Library and online guide for .NET Barcode Generation, ASP.NET Barcode Generation, C# Barcode Generation, VB.NET Barcode Generation, .NET Barcode Reading, Barcode Generation Software.