Barcode to Stream
Barbecue is a free and open source Java library for Barcode generation.
This requires the library barbecue-1.5-beta1.jar to be in classpath.
The following example shows streaming CODE 128B Barcode to OutputStream.
package com.bethecoder.tutorials.barbecue;
import java.io.FileOutputStream;
import java.io.OutputStream;
import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;
public class BarCode2StreamTest {
public static void main ( String [] args ) throws Exception {
//Get 128B Barcode instance from the Factory
Barcode barcode = BarcodeFactory.createCode128B ( "be the coder" ) ;
//Ouput stream to File/Socket/servlet response stream
OutputStream outStream = new FileOutputStream ( "teststream.png" ) ;
//Write the bar code to OutputStream
BarcodeImageHandler.writePNG ( barcode, outStream ) ;
}
}
It gives the following output,