BAR Code Generation in Java

Add the following jar into Class path and Lib folder in project

1.barcode.jar

Source Code:

package javapages4all;

import com.keepdynamic.barcode.generator.BarCode;

public class BARCodeGeneration {

/**
* @param args
*/
public static void main(String[] args)
{
try {
/**
* create BARCODE Class Object
*/
BarCode barcode = new BarCode();

/**
* set barcode properties
*/
barcode.setSymbologyType(BarCode.CODE128);
barcode.setCodeText(“Raja”);
/**
* disable Text displaying below Code
*/
barcode.setDisplayCodeText(false);

/**
* create image object
*/
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(300,300,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED );

/**
* get graphic context of image
*/
java.awt.Graphics2D imgGraphics = image.createGraphics();

/**
* draw barcode to specified location in Rectangle
*/
barcode.paintBarCode(imgGraphics, new java.awt.Rectangle(0, 0, 300, 300));
barcode.drawBarCode2Image(“/home/raja/Java/barimg.jpg”);
} catch (Exception e)
{
e.printStackTrace();
}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: