Linear Java Bar Code Package
Barcoding with the BarCode class:
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.
For
information on Java bean operation please review BeanInfo.html.
You may also wish to review the index of fields and
methods. To hide the text below the barcode, make the "fontColor"
the same as the "backColor".
- barType (parameter CODE_TYPE in applet, default is code 128): this is the type of
barcode to be used. Valid values are: CODE39, CODE39EXT, CODE11, CODABAR, CODE93EXT, CODE128, MSI, IND25, MAT25, INTERLEAVED25, EAN13, EAN8,
CODE128, POSTNET, PLANET, UCC128, 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 characters 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 text and font used to display the
code. Make this the same as the Background Color to hide the text.
- guardBars (GUARDS_BARS): indicates if guard bars will be a height
other than other bars. Only for EAN and UPC.
- I (parameter I in applet): inter-character separator, only for
CODE39. 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 value is 2.
- postnetHeightTallBar: height (in CM) of POSTNET
tall bars.
- postnetHeightShortBar: height (in CM) of POSTNET
short bars.
- resolution: the resolution used to convert from CM to pixels. The
default is the screen resolution of pixels per CM. This is obtained by
resolution=(int) (this.getToolkit().getScreenResolution()/(2.54)).
- rotate (ROTATE): Indicates how the barcode should be painted. Valid values are 0
(normal), 90 (vertical),180 (inverted)
and 270 (inverted vertical).
- supHeight (SUPPLEMENT_HEIGHT): relative height of the EAN or UPC
supplement
bars. 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 human readable code.
- topMarginCM (TOP_MARGIN): top margin in CM.
- UPCEANSupplement2 (SUPPLEMENT=2): indicates if the codes EAN
and UPC will have a 2 digit supplement.
- UPCEANSupplement5 (SUPPLEMENT=5): indicates if the codes EAN
and UPC will have a 5 digit supplement.
- UPCESystem (UPCE_SYSTEM): encoding system to be used for UPC-E,
valid values are 0 and 1.
- X (parameter X in applet): width in centimeters of narrow bars.
The default is 0.03. Set this value to .001 to obtain the smallest barcode
possible which is 1 pixel.
Servlet Operation and JPEG or GIF File Encoder Example
Before you can create a GIF or JPEG file with the Java Package, you must make
sure you meet the following requirements:
- Place the jar or class files in the CLASSPATH - in Windows,
this is accomplished by modifying the CLASSPATH environment variable to include
the full path to the JAR file. For example, the following will add
LinearBarCode.jar to the classpath:
SET CLASSPATH=.;c:\java\classroot\;c:\jars\LinearBarCode.jar
You can also extract the files in the JAR files to the classpath
root, making sure the proper directories defined in the JAR are
created.
- Use JDK 1.2 or above - the encoder requires Java 2 or JDK 1.2
or above to create the GIF or JPEG files. This is a requirement of the
encoder that creates the files, not the class library.
- Java.awt GUI functions must be available in your environment
- this is not usually an issue with Windows NT and Windows 2000
servers. In UNIX, if your Java environment has the java.awt library stripped out, then you will be unable to use our
Java products. If your UNIX server does not have an X-Window environment, you must connect to a remote X
Server or install the X Windows environment and run an X Windows
session.
How to create a GIF or JPEG file:
This is a very simple example of the Java source code used to create a
GIF file from the Linear Barcode Package.
import com.idautomation.linear.*;
import com.idautomation.linear.encoder.*;
class CreateGIF {
public static void main ( String [] args ) {
BarCode bc=new BarCode();
bc.code="123456789";
bc.barType=bc.CODE128;
bc.setSize(400,200);
barCodeEncoder bce = new barCodeEncoder(bc, "GIF", "newfile.gif");
}
}
How to use the Servlet:
- Install the appropriate
servlet server code on your server and make sure it is in the
CLASSPATH also. For example:
SET CLASSPATH=.;c:\java\classroot\;c:\jars\LinearBarCode.jar;c:\jsdk2.1\server.jar;c:\jsdk2.1\servlet.jar
- Per the JSDK instructions, we edit servlets.properties
to include the following statement:
LinearServlet.code=com.idautomation.linear.IDAutomationServlet
- Next, we start the servlet server by executing C:\jsdk2.1\startserver.bat.
- After the servlet server is started, we can type the following code
into our browser and specify applet parameters to create the barcode.
This URL creates the a barcode encoding "12345678" with a
height if .8CM:
http://localhost:8080/examples/servlet/LinearServlet?BARCODE=12345678&BAR_HEIGHT=.8
- We can also create a barcode within webpages and HTML forms by using
an IMG tag, for example:
<img src="http://localhost:8080/examples/servlet/LinearServlet?HEIGHT=80&WIDTH=170&BARCODE=12345678&BAR_HEIGHT=.8">
Notice also in the above code that the HEIGHT and BAR_HEIGHT
are different. The HEIGHT and WIDTH parameter should be set to the
maximum allowed barcode size within a form.
- Other methods of servlet operation can be accomplished by advanced
programmers that modify the servlet source code we provide. However,
these methods cannot be supported by tech support.
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:
BarCode bc=new BarCode();
bc.setSize(400,200); // important - set the 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 supplying 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.
EAN and UPC symbologies have a fixed length, 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.
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 CODE = "com.idautomation.linear.BCApplet"
NAME = "TestApplet" WIDTH = 500 HEIGHT = 100 HSPACE = 0 VSPACE
= 0 ALIGN = middle >
<PARAM NAME = "BARCODE" VALUE = "12345667">
<PARAM NAME = "CODE_TYPE" VALUE = "CODE39">
<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:
- UCC128: This symbology option adds in the FNC1 function and formats
the output to Code 128 set C. Use this function for UCC/EAN-128 applications
when you have already generated your MOD10 check digit if required. Supports
UCC-128, EAN-128, SSCC-18 and SCC-14. For example, to encode an SSCC-18
barcode, you would enter 00000123455555555558 as the data input. The FNC1 code
is automatically included after the start digit, you may also enter "ΚΚ"
between even numbers for additional FNC1 codes (For example 123456ΚΚ7890). Review the Code
128 Data Sheet and FAQ for more information on this.
- CODE39: Code 39 is an alphanumeric barcode that can encode
numbers, upper case letters, and the following special symbols: _
. * $ / % +. If the CHECK_CHAR flag is set the Java BarCode Class will calculate the
optional check character (modulus 43) which is recommended for LOGMARS. LOGMARS (Logistics Applications of Automated Marking and Reading Symbols) is an application of Code 39 used by the United States Department of Defense that recommends a check character. LOGMARS is defined by Military Standard MIL-STD-1189B.
Review the Code
39 Data Sheet and FAQ for more information on this barcode.
- CODE39EXT: Extended Code 39 encodes the full 128 character ASCII
character set. If the CHECK_CHAR flag is set the Java BarCode Class will calculate the optional
check character (modulus 43) which is recommended for LOGMARS. Review the Code
39 Data Sheet and FAQ for more information on this barcode.
- CODE128: Code 128 is a continuous, multilevel, full ASCII code with
three character sets.
If the CHECK_CHAR flag is set the Java BarCode Class will calculate the mandatory check
character (modulus 103). Review the Code
128 Data Sheet and FAQ for more information on this barcode.
- INTERLEAVED25: Interleaved 2 of 5 code is a numeric only bar
code. If the CHECK_CHAR flag is set the Java BarCode Class will calculate the optional
modulus 10 check character.
- UPCA: UPC-A is used for marking retail products 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.
- 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.
- 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: EAN-13 encodes 13 digits: 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.
- MSI: The MSI Code is a numeric barcode that has been used primarily in libraries and retail applications such as grocery store shelves. If the CHECK_CHAR flag is set the Java BarCode Class
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 the Java BarCode Class 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 the Java BarCode Class will calculate
the modulus 43 check character.
- IND25: Industrial 2 of 5 (also called Code 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 the Java BarCode Class will calculate the optional
modulus 16 check character.
- POSTNET and PLANET: Enter the entire number to be encoded without any
spaces or dashes. For barcodes to be easily scanned at the US post offices,
they should be between 22 and 24 bars per inch. The default X setting of .03CM
should produce about 24 bars per inch.
For more information about the barcode symbologies, please visit
our BizFonts.com site and select the symbology.