Barcode4J is a free and flexible Java library for Barcode generation.
This requires the libraries barcode4j.jar, avalon-framework-4.2.0.jar to be in classpath.
The following example shows generating CODE 2of5 Barcode with orientation.
BarcodeUtil util = BarcodeUtil.getInstance();
BarcodeGenerator gen = util.createBarcodeGenerator(buildCfg("2of5"));
OutputStream fout = new FileOutputStream("2of5ori.jpg"); int resolution = 200; int orientation = -270; //Orientation must be 0, 90, 180, 270, -90, -180 or -270
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
fout, "image/jpeg", resolution, BufferedImage.TYPE_BYTE_BINARY, false, orientation);
//Bar code type
DefaultConfiguration child = new DefaultConfiguration(type);
cfg.addChild(child);
//Human readable text position
DefaultConfiguration attr = new DefaultConfiguration("human-readable");
DefaultConfiguration subAttr = new DefaultConfiguration("placement");
subAttr.setValue("bottom");
attr.addChild(subAttr);