Tutorial

BarCode/JSP allows you to do dynamic barcode image generation using either a servlet or a JSP page. Two graphics formats are supported: JPEG and PNG:

- Dynamic JPEG Image
- Dynamic PNG Image

Other topics that you may need to be aware of:

- Barcode Size and Printer Resolution
- Threading Model

Dynamic JPEG Image

You can use dynamic barcode JPEG images in any HTML pages and this doesn't require any scripting. Simply embed, for example,
	<img src="..../BarcodeServlet?image=3&type=6&data=12345678">
or
	<img src="barcode.jsp?image=3&type=6&data=12345678">
in your HTML file and, voila, you have a dynamically generated Code 39 barcode image.

The advantage of the JPEG image format is that it's supported by virtually all commercial grade browsers in all their versions.

It's well-known that JPEG uses lossy image compression. BarCode/JSP generates JPEG with high quality (thus low compression). The result is fairly good. However, you may see background noises when printing using Netscape; we think that's because Netscape adopts a low quality decompression approach (yes, like compression, you can specify a quality parameter for decompression, too). Fortunately, our tests show that the result is still scannable in our test conditions (300 dpi laser printer).

Dynamic PNG Image

BarCode/JSP also generates barcode images in the PNG format, in addition to JPEG. You use PNG image generation the same way you would JPEG. For example, the following HTML mark-up will generate a barcode image in PNG format:
	<img src="..../BarcodeServlet?image=1&type=6&data=12345678">
or
	<img src="barcode.jsp?image=1&type=6&data=12345678">
Unlike JPEG, PNG uses lossless image compression and gives you high quality images. The only drawback is that PNG is only supported by recent browsers (i.e., IE 4.0 or later and Netscape 4.04 or later). If you're target these browsers, we highly recommend you use the PNG image format.
Why Not GIF?
GIF is not supported for legal reasons. We'll support GIF when there's enough demand for it. In fact, any web site operators who use GIF generation software on their web site would need to pay a substantial amount in royalty fees to Unisys Coporation (several thousand dollars as of this writing), in addition to any up-front fees that the software developer would have to pay it.

Barcode Size and Printer Resolution

The minimum barcode width on the screen is given by the NumModules property. The barcode width can only be a multiple (1, 2, etc.) of this minimum width. You can change the scale factor when using barcode.jsp, e.g. <img src=..../BarcodeServlet.jsp?barwidth=2> will use a scale factor of 2; if you script the BarCode/JSP component directly, you can set this scale factor in makeSimpleImage/makeImage, saveSimpleImage/saveImage or enumerateBars. While different bar widths are in proportion on the screen, the printed version may be slightly different. The higher the printer resolution, the better the result will be. If the printer resolution is low, you may need to use a scale factor of 2 or higher, so that the printed barcode is scannable. Note that this is different from applications using directly BarCode/OCX or DLL, in which case the barcode component has the opportunity to tune the barcode directly according to the destination printer resolution.

If you find the barcode size too big, you can specify a WIDTH attribute value for the <IMG> tag. This does not compromise the intrinsic barcode image quality as it comes down from the server; the image is simply scaled back at display time on the screen.

Threading Model

If you have to script BarCode/JSP directly, you need to know that a Barcode instance is not thread safe. This means each Barcode instance can only be accessed safely from within a single thread (you can have multiple instances belonging to different threads, though). This is perfectly fine within an HTTP servlet's service, doGet or doPost method and within a JSP page, as long as you create a new instance each time and are done with it upon leaving the method or JSP page.