Monthly Archives: June 2013

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

QR Code Generation in Java

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

1.zxing-core-1.7.jar

2.qrgen-1.0.jar

3.zxing-j2se-1.7.jar

Source Code:

package javapages4all;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
public class QRCodeGeneration {

/**
* @param args
*/
public static void main(String[] args)
{
ByteArrayOutputStream out = QRCode.from(“Raja”).to(ImageType.PNG).stream();
try
{
/**
* set the output Image Location
*/
FileOutputStream fout = new FileOutputStream(new File(“/home/raja/Java/QR_Code_raja.JPG”));
fout.write(out.toByteArray());
fout.flush();
fout.close();

} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}

}

 

%d bloggers like this: