RBarCode
Wellcome to RBarCode. This package contains a java applet and a java
class you can use to create barcodes for you website or java application.
BarCode
This section explains the main configuration parameters of the BarCode
class. This class is a descendant of java.awt.Canvas and you can therefore
use it in any java container.
The names in parenthesis are the names of the applet parameters.
- barType (parameter CODE_TYPE in applet): this is the type of
barcode to be used. Valid values are: BAR39, BAR39EXT, CODE39, CODE11,
CODABAR, CODE93EXT, CODE128, MSI, IND25, MAT25, INTERLEAVED25, EAN13, EAN8,
CODE128, POSTNET, UPCA and UPCE.
- backColor (BACK_COLOR): back color of the barcode.
- barColor (BAR_COLOR): color of the bars.
- barHeightCM (parameter BAR_HEIGHT in applet): height of the
bars in CM. If this value is 0, it will be calculated using H.
- CODABARStartChar (CODABAR_START): Start character for CODABAR.
Valid values are "A", "B", "C" or "D".
- CODABARStopChar (CODABAR_STOP): Stop character for CODABAR.
Valid values are "A", "B", "C" or "D".
- code (parameter BARCODE in applet): this is the value to be
encoded.
- code128set (parameter CODE128_SET in applet): set of charaters
to be used in code128. Valid values are : A, B or C.
- checkCharacter (CHECK_CHAR): If true the software will calculate
the check character automatically. The applet converts "Y" to
true and "N" to false.
- fontColor (FONT_COLOR): color of the font used to display the
code.
- guardBars (GUARDS_BARS): indicates if guardbars will be height
than other bars. Only for EAN and UPC.
- I (parameter I in applet): intercharacter separator , only for
BAR39. A value of 1 means that the separator will have the same length
as X.
- H (parameter H in applet): Indicates how to calculate the height
of the bars. A value of 0.5 means that the bars should be half the length
of the symbol.
- leftMarginCM (LEFT_MARGIN): left margin in CM.
- N (parameter N in applet): a value of 2, means that wide bars
will be 2 times the width of narrow bars. The default vaue is 2.
- postnetHeightTallBar: height (in CM) of PostNet's
tall bar.
- postnetHeightShortBar: height (in CM) of PostNet's
short bar.
- PDFColumns (only for Barcode2D) (PDF_COLUMNS): number of columns
for PDF417 (the default is 10).
- PDFECLevel (only for Barcode2D) (PDF_ECLEVEL): error correction
level for PDF417 (the default is 0).
- PDFMode (only for Barcode2D) (PDF_COMPACTION): PDF417 mode can
be NUMERIC, TEXT or BINARY.
- PDFRows (only for Barcode2D) (PDF_ROWS): number of rows for
PDF417 (optional).
- rotate (ROTATE): Indicates how the barcode should be painted (vertica,
horizontal ...). Valid values are 0 (nomral), 90 (vertical),180 (inverted)
and 270 (inverted vertical).
- supHeight (SUPPLEMENT_HEIGHT): relative height of the supplement's
bars (only EAN and UPC). The default (0.8) means 80% of the normal
bars.
- supSeparationCM (SUPPLEMENT_SEPARATION): separation between
the code and the supplement (in CM). the default is 0.5 (only EAN and UPC).
- textFont (TEXT_FONT): font used to display the code.
- topMarginCM (TOP_MARGIN): top margin in CM.
- UPCEANSupplement2 (SUPPLEMENT=2): indicates if the codes EAN
and UPC will have a 2 digit's supplement.
- UPCEANSupplement5 (SUPPLEMENT=5): indicates if the codes EAN
and UPC will have a 5 digit's supplement.
- UPCESystem (UPCE_SYSTEM): encoding system to be used for UPCE,
valid values are 0 and 1.
- X (parameter X in applet):: width in centimeters of narrow bars.
The default is 0.03.
How to create a gif or jpg file.
You can also export the barcode to a gif or a jpeg file. In order to
do this you must use the following code:
import MSBBarCode.*;
import MSBBarCode.encoder.*;
bc=new BarCode();
bc.setSize(400,200); // important, set size
....
new barCodeEncoder(bc,"GIF","file.gif");
new barCodeEncoder(bc,"JPEG","file.jpg");
note that:
- The GIF encoder has been provided by Acme (http://www.acme.com)
- In order to use the JPEG encoder you must have the package com.sun.image.codec.jpeg
installed.
Note: this feature is only available in JDK 1.2 or later.
How to create the barcode in a java.awt.Image object
The following code illustrates how you can create a barcode in a java.awt.Image
object:
bc=new BarCode();
bc.setSize(400,200); // important, set size
// create image
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(
bc.getSize().width,bc.getSize().height,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED
);
// get graphic context of image
java.awt.Graphics imgGraphics = image.createGraphics();
// paint barcode in graphics context of image
bc.paint(imgGraphics );
How to use the checkCharacter (CHECK_BAR) field:
If you are suppling the code with the check digit already calculated,
you must set CHECK_CHAR to N (this is the default). If you want the
software to calculate the checksum for you, you must set CHECK_CHAR to
Y.
For EAN and UPC have fixed length and therefore you only have the following
possibilities:
- EAN13: you supply a 13 digits code and set CHECK_CHAR to N or you supply
a 12 digits code and set CHECK_CHAR to Y.
- EAN8: you supply a 8 digits code and set CHECK_CHAR to N or you supply
a 7 digits code and set CHECK_CHAR to Y.
- UPCA and UPCE: you supply a 12 digits code and set CHECK_CHAR to N
or you supply a 11digits code and set CHECK_CHAR to Y.
How to use RBarcode in a web site
You have two possibilities:
- Use the applet to create barcodes in the browser. In this case
you must create HTML dinamically. The HTML page will contain the applet
and the parameters.
- Use a servlet to create a gif or jpeg image in the server and
send the to the browser. See RBarcodeServlet.java for an example.
BCApplet
You can use BCApplet to display barcodes in your HTML pages.Some parameters
of the applet have a special format:
- Colors: valid values are: RED,BLUE,GREEN,BLACK,GRAY,LIGHTGRAY,WHITE,DARKGRAY,YELLOW,ORANGE,CYAN
and MAGENTA. You can also use the RGB numerical value of a color as parameter
(e.g. 0x00FF00 if green).
- Fonts have the format <font name>|<style>|<size>.
Style can be PLAIN, ITALIC or BOLD. Example: "Arial|BOLD|12"
Example of how to use the applet:
<APPLET CODEBASE = "./" CODE = "MSBBarCode.BCApplet.class"
NAME = "TestApplet" WIDTH = 500 HEIGHT = 100 HSPACE = 0 VSPACE
= 0 ALIGN = middle >
<PARAM NAME = "BARCODE" VALUE = "12345667">
<PARAM NAME = "CODE_TYPE" VALUE = "CODE11">
<PARAM NAME = "BAR_COLOR" VALUE = "RED">
<PARAM NAME = "BACK_COLOR" VALUE = "YELLOW">
<PARAM NAME = "LEFT_MARGIN" VALUE = "1">
<PARAM NAME = "TOP_MARGIN" VALUE = "1">
<PARAM NAME = "FONT_COLOR" VALUE = "BLUE"> <
PARAM NAME = "TEXT_FONT" VALUE = "ARIAL|BOLD|14">
<PARAM NAME = "CHECK_CHAR" VALUE = "Y">
<PARAM NAME = "BAR_HEIGHT" VALUE = "1"> </APPLET>
You can provide the parameters in the Applet PARAM tag or you can also
do it from Javascript. For example, the following code set a new
value for the barcode:
TestApplet.setParameter(BARCODE,"new value");
TestApplet.refresh();
Barcodes types
The following is a short description of some of the barcode types:
- BAR39: Code 39 is an alphanumeric bar code that can encode decimal
numbers, the upper case alphabet, and the following special symbols: _
. * $ / % +. If the CHECK_CHAR flag is set RBarCode will calculate the
optional check character (modulus 43).
- BAR39EXT: Extended Code 39 encodes the full 128 character ASCII
character. If the CHECK_CHAR flag is set RBarCode will calculate the optional
check character (modulus 43).
- INTERLEAVED25: Interleaved 2 of 5 code is a numeric only bar
code. If the CHECK_CHAR flag is set RBarCode will calculate the optional
modulus 10 check character.
- UPCA: UPC-A is used for marking products which are sold at retail
in the USA. Version A encodes a twelve digit number. The first number encoded
is the number system character, the next ten digits are the data characters,
and the last digit is the check character.
- EAN8: EAN-8 is a shortened version of the EAN-13 code. It includes
a 2 or 3 digit country code, 4 of 5 data digits (depending on the length
of the country code), and a checksum digit.
- EAN13: The symbol encodes 13 characters: the first two or three
are a country code which identify the country in which the manufacturer
is registered (not necessarily where the product is actually made). The
country code is followed by 9 or 10 data digits (depending on the length
of the country code), and a checksum digit.
- UPCE: The UPC-E code is a compressed barcode which is intended
for use on small items. Compression works by squeezing extra zeroes out
of the barcode and then automatically re-inserting them at the scanner.
Only barcodes containing zeroes are candidates for the UPC-E symbol.
- CODE128: Code 128 is a continuous, multilevel, full ASCII code.
If the CHECK_CHAR flag is set RBarCode will calculate the mandatory check
character (modulus 103).
- MSI: MSI Code is a numeric. If the CHECK_CHAR flag is set RBarCode
will calculate the modulus 10 check character.
- CODE11: Code 11 is a numeric, high density code with one special
character - .If the CHECK_CHAR flag is set RBarCode will calculate check
character. If the value to be encoded is longer than 10 digits, a second
check character will be calculated.
- CODE93: Code 93 is a more compact version of Code 39. It encodes
exactly the same characters as Code 39, but uses 9 barcode elements per
character instead of 15. If the CHECK_CHAR flag is set RBarCode will calculate
the optional modulus 43 check character .
- IND25: Industrial 2 of 5 is a numeric-only barcode that has
been in use a long time. Unlike Interleaved 2 of 5, all of the information
is encoded in the bars; the spaces are fixed width and are used only to
separate the bars. The code is self-checking and does not include a checksum.
- CODABAR: Codabar is a discrete, numeric code with special characters
(-$:/.+). If the CHECK_CHAR flag is set RBarCode will calculate the optional
modulus 16 check character .
At
HP site you will find more information abour barcode.