Java Barcode Generator, .NET Barcode Generator for C#, ASP.NET, VB.NET
HOME PURCHASE SITEMAP COMPANY

Home > Barcode for Java > Java Barcode Generation Guide

Download Java Barcode Trial Package

Java Barcode Generation Guide

Generating linear & 2D barcode images using Barcode for Java library, is a simply and easy task.

This page is a demonstration and guide of what & how you can do with Java Barcode Generator library in your Java projects.



Quick access:     Overview   |   Installation   |   for Java Class   |   for Java Web   |   for Java Reporting   |   Barcode Properties

 

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 frameworks (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 library
  • /barcode, contains Barcode for Java Buildin Barcode Generation web application for developers. See howto.
  • LicenseAgreement.txt, Barcode for Java End-User License Agreement

 

Install Barcode for Java library


 

How to Generate Barcodes in Java Class?


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

The following Java code illustrates how to generate a 1d (linear) barcode in a 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 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)

Generate Data Matrix barcodes 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 DataMatrix barcode object (line 1)
  • set DataMatrix object barcode properties (line 2)
  • Generate data matrix barcode and encode into gif image 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)

Generate PDF-417 barcodes 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)

Generate QR-Code barcodes 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 QRCode barcode object (line 1)
  • set QRCode object barcode 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 to generate barcode image is to use our Buildin 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 java_barcode_trial, 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 is similar with the way to generate barcode in Java class.

    • Create a barcode & save the barcode image to your server side
      1	Linear linear = new Linear(); 
      2	linear.setData("123456789"); 
      3	linear.setType(Linear.CODE128); 
      4	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?


 

Barcode for Java Each Barcode Symbology Property Settings


1D (Linear) Barcode Types/Symbologies


2D (Matrix) Barcode Types/Symbologies

 

 

Java Barcode Generator Support


Send your questions to support@barcodelib.com







   Copyright 2010 BarcodeLib.com. Provides High Quality Java Barcode Generator, Barcode Generator Java, Java Bar Code Generator. All rights reserved.