Java Barcode
Package User Manual & Tutorial
INDEX:
If a barcode scanner is needed, IDAutomation provides several types of
high-quality USB Barcode
Scanners.
IDAutomation's Java Barcode Packages are mature barcode generator
components that have been in use since 2000. Multiple capabilities of
this product are provided in a single JAR file to ease installation, use
and upgrades. All IDAutomation Java Barcode Packages include the
following components:
- Barcode class library - includes all necessary class files
for java barcode generation.
- Applet - allows easy applet
implementation.
- Servlet - enables servlet
use with applet parameters.
- Encoder - used to convert java.awt images obtained from the
barcode class into JPEG or GIF files.
- Source code - includes source code to the applet, servlet,
encoder and examples. The source code for the java barcode generator
class should not be needed; however, it is available with the purchase
of the
Unlimited
Developer License and a signed
Source
Code License Agreement.
This Java library is easily utilized after the JAR file is installed in
the Java
classpath
environment. There are some exceptions, such as when integrating source
code or class files directly, or
servlet implementation with
Apache Tomcat. However, for most purposes, the JAR file must be
installed.
The following example uses the Linear Java Barcode Package. When using
other packages, the associated file should be replaced accordingly.
- Install Java and ensure the Java executables are included in the
search path. For example: after installing JDK 1.3 in Windows,
c:\jdk1.3\bin
must be appended to the
path
environment variable so that the complete path looks something like
%SystemRoot%\system32;%SystemRoot%;c:\jdk1.3\bin. In Windows®,
the path environment is created or edited by choosing My Computer -
Properties - Advanced System Settings - Environment Variables.
- Copy LinearBarCode.jar
from the package to C:\IDAutomation or a production directory of choice.
- Add both the JAR file and the period to the
classpath
environment variable. The specification of the JAR file enables the
barcode library to be available for Java programs. The period allows
Java applications to run in the current directory, which is convenient
for testing. In Windows, the classpath environment variable may be
created or edited by choosing My Computer - Properties - Advanced System
Settings - Environment Variables. The classpath should look something
like
C:\IDAutomation\LinearBarCode.jar;.
The "SET CLASSPATH" command may be used from the command prompt to
verify that classpath.
- Download
IDAutomation_LinearJavaEncoderTestApplication.zip
and extract the files into a temp directory such as c:\temp. From the
temp files extracted, execute the CreateJPEG class file in Java; Windows
users may simply execute run.bat instead. When asked, enter the data of
"IDAUTOMATION" and verify a JPEG file is created.
- If problems are encountered, verify the above steps were completed
properly and ensure the Java.awt GUI functions are available. If the
Java environment has the java.awt library stripped out or the system
running Java does not have an active GUI environment, either (1) use
Headless Java or (2) connect to a remote X Server or (3) install the X
Windows environment and run an X Windows session or (4) install an
emulator, PJA library or virtual frame buffer as described in the
XWindow
Error KB Document.
Java Applets are included with all IDAutomation JAR files of the
Java Barcode Packages. An
applet may be used to easily display barcodes in Web pages with
compatible Web
browsers. An example of using the applet in HTML is provided in the
package download. Properties are modified by changing the appropriate
Applet Parameter.
HTML Code Example:
<APPLET CODEBASE = "./"
ARCHIVE = "LinearBarCode.jar"
CODE = "com.idautomation.linear.BCApplet.class"
NAME = "TestApplet"
WIDTH = 500 HEIGHT = 200 HSPACE = 0 VSPACE = 0 ALIGN = middle >
<PARAM NAME = "BARCODE" VALUE = "123456789012">
<PARAM NAME = "CODE_TYPE" VALUE = "CODE39">
<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 = "N">
<PARAM NAME = "BAR_HEIGHT" VALUE = "2"> </APPLET>
The size must be specified when using the applet. Parameters may be
provided in the Applet PARAM tag or from
Javascript. For example, the following code will set a new value for
the barcode:
TestApplet.setParameter(BARCODE,"new
value");
TestApplet.refresh();
Applet Pre-Loading
The time it takes to create barcodes on Web pages using applets may be
reduced by pre-loading the applet on a previous page. This type of
implementation places the JAR file in the browser's cache and allows
quick barcode generation. The following JavaScript code pre-loads the
Linear Barcode Package.
<APPLET
CODE = "com.idautomation.linear.BCApplet"
ARCHIVE = "LinearBarCode.jar"
NAME = "PreloadApplet"
WIDTH = 1 HEIGHT = 1 HSPACE = 0 VSPACE = 0 ALIGN = top >
</APPLET>
| JPEG
& GIF Encoder Example |
The following is a very simple example of the Java source code used to
create an image file from the Linear Java Barcode Package:
import
com.idautomation.linear.*;
import com.idautomation.linear.encoder.*;
class CreateImageExample {
public static void main ( String [] args ) {
BarCode bc=new BarCode();
bc.code="123456789012";
barCodeEncoder bce = new barCodeEncoder(bc,
"GIF", "newfile.gif");
System.exit(0);
}
}
Additional examples are provided in the package download for each
symbology.
Java Servlets are included with all IDAutomation JAR files of the
Java Barcode Packages and
may be used to add server-side barcode generator capability to a
dedicated Web server. IDAutomation servlets are compatible with all
browsers and are easy to embed in HTML as an image with the <IMG> tag.
In addition, IDAutomation java servlet barcodes may be streamed into
reports that support dynamic image objects, including
Crystal Reports and
FileMaker. Properties of the servlet are modified by changing the
appropriate
Applet Parameter.
Java Barcode Servlet
Implementation:
IDAutomation offers a tutorial for
servlet implementation with Apache Tomcat. Additional examples are
provided below.
Servlet Example with
Java Barcode
Servlet SDK:
- Install and test the barcode JAR file.
- Install
Java
Servlet SDK on the server and make sure it is specified in the
classpath. For example:
SET
CLASSPATH=.;c:\java\classroot\;c:\jars\LinearBarCode.jar;c:\jsdk2.1\server.jar;c:\jsdk2.1\servlet.jar
- Per the
Java
Servlet SDK instructions, edit
c:\jsdk2.1\examples\WEB-INF\servlets.properties
to include the following statement:
LinearServlet.code=com.idautomation.linear.IDAutomationServlet
- Start the servlet server by executing
C:\jsdk2.1\startserver.bat.
- After the servlet server is started, paste the following text into a
Web browser:
http://localhost:8080/examples/servlet/LinearServlet?BARCODE=12345678
Servlet Implementation Using
ServletExec ISAPI on Windows® Server:
- In the servlet administration area, choose Configure.
- Choose Add Servlet and enter the servlet name, class and code
base.
- Choose Submit and choose to Reload
the new servlet.
- The servlet should now be viewable online by entering a URL such as
http://yourserver.com/servlet/LinearServlet?BARCODE=12345678
Inserting Java Barcodes in HTML:
- Barcodes may be integrated within Web pages and HTML forms by use of
the IMG tag, for example:
<img
src="http://yourserver.com/servlet/LinearServlet?BARCODE=12345678">
- The image that is created defaults to 96 dpi and may be
compressed
or expanded if necessary to obtain better precision.
Creating Secure Servlets:
Other methods of servlet operation may be accomplished by developers
that modify the servlet source code provided. This may be necessary to
ensure the end-user cannot manipulate the servlet. A working example is
provided in the IDAutomationSecureServlet.java
file, which is in the source code ZIP file in the package.
Auto-sizing and Performance
Considerations:
When using the Servlet, auto sizing of the image is disabled if the
HEIGHT and WIDTH are manually specified. Because a temp image is created
to determine the size, performance is improved by specifying the size.
The following code illustrates how to create a barcode in a
java.awt.Image object:
BarCode bc=new BarCode();
bc.setSize(400,200);
// 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 );
This section explains the main properties, methods and configuration
parameters of the package. This class is a descendant of java.awt.Canvas
and may be used in any java container. IDAutomation suggests leaving
all properties at their defaults unless they absolutely need to be
changed.
|
Properties and Methods
(Refer to the
index of
fields and methods for more detailed API information)
|
| Class Properties |
Applet Properties |
Default |
Comments |
|
AutoSize
|
AUTO_SIZE
|
True
|
If true, the size the barcode image will automatically be
determined. If this is set to false, the size will need to be
specified with setSize(w,h). Because a temp image is created to
determine the size, performance is improved by specifying the size
and setting autoSize to false.
|
|
SymbologyID
|
CODE_TYPE
|
CODE128
(13)
|
This is the type of barcode to create. Valid values for the
barcode types are as follows:
CODE39=0;
CODE39EXT=1;
INTERLEAVED25=2;
CODE11=3;
CODABAR=4;
MSI=5;
UPCA=6;
IND25=7; MAT25=8;
CODE93=9;
EAN13=10;
EAN8=11;
UPCE=12;
CODE128=13;
CODE93EXT=14;
POSTNET=15;
PLANET=16;
UCC128=17;
ONECODE=18; the default is CODE128. Use the number value for
the JavaBean and the text value for the applet and servlet.
For example, the servlet query string would include:
&CODE_TYPE=ONECODE
|
|
Background
|
BACK_COLOR
|
WHITE
|
The background color of the barcode. It is recommended to use the
default setting of WHITE. Valid values are: RED, BLUE, GREEN, BLACK,
GRAY, LIGHTGRAY, WHITE, DARKGRAY, YELLOW, ORANGE, CYAN and MAGENTA.
The RGB numerical value of a color can also be used as a parameter
(e.g. 0x00FF00 for green).
|
|
Foreground
|
BAR_COLOR
|
BLACK
|
The color of the bars. It is recommended to use the default
setting of BLACK. Valid values are: RED, BLUE, GREEN, BLACK, GRAY,
LIGHTGRAY, WHITE, DARKGRAY, YELLOW, ORANGE, CYAN and MAGENTA. The
RGB numerical value of a color can also be used as a parameter (e.g.
0x00FF00 if green).
|
|
BarHeightCM
|
BAR_HEIGHT
|
1
|
The height of the bars in CM, which also adjusts the entire
height of the barcode.
|
|
bearerBarHorizontal
|
BEARERBAR_HORIZONTAL
|
0
|
The size of the horizontal bearer bars. Valid values are 0-10
which are a multiple of X.
|
|
bearerBarVertical
|
BEARERBAR_VERTICAL
|
0
|
The size of the vertical bearer bars. Valid values are 0-10 which
are a multiple of X.
|
|
characterGrouping
|
CHARACTER_GROUPING
|
0
|
The number of digits, which will be grouped together in the human
readable text. Valid values are 0,3,4, and 5.
|
|
CODABARStartChar
|
CODABAR_START
|
A
|
Start character for CODABAR. Valid values are "A", "B", "C" or
"D".
|
|
CODABARStopChar
|
CODABAR_STOP
|
B
|
Stop character for CODABAR. Valid values are "A", "B", "C" or
"D".
|
|
DataToEncode
|
BARCODE
|
na
|
This is the data text to be encoded in the barcode. The input is
a string value type. A
byte
array may also be use in PDF417 or DataMatrix.
|
|
Code128Set
|
CODE128_SET
|
0
|
The set of characters to be used in Code 128. Valid values are:
0, A, B or C. 0 is used for the automatic selection. It is
recommended to leave this at the default setting.
More about Auto Function...
|
|
CheckCharacter
|
CHECK_CHAR
|
Y
|
If true, the software will calculate the check character
automatically. The applet and servlet convert "Y" to true and "N" to
false.
|
|
TextFontColor
|
FONT_COLOR
|
BLACK
|
The color of the text below the barcode. Valid values are: RED,
BLUE, GREEN, BLACK, GRAY, LIGHTGRAY, WHITE, DARKGRAY, YELLOW,
ORANGE, CYAN and MAGENTA. The RGB numerical value of a color can
also be used as a parameter (e.g. 0x00FF00 if green).
|
|
(see example)
|
FORMAT
|
JPEG
|
Determines the format of the image when using the servlet or
saving a barcode image to a file. Valid values are GIF and JPEG. The
GIF files generated are typically 4 to 20 times smaller in size than
the JPEG files.
|
|
LeftMarginCM
|
LEFT_MARGIN
|
.3
|
The left margin in CM. This may need to be increased for UPC and
EAN barcode types.
|
|
NarrowToWideRatio
|
N
|
2
|
The wide to narrow ratio. A value of 2 (the default), means that
wide bars will be 2 times the width of narrow bars. This setting is
only valid for barcode types that support an N dimension such as
Code 39 and ITF.
|
|
PixelsPerCM
|
na
|
38
|
The resolution used to create the X dimension and other
measurements in pixels; Default is 38 Pixels Per CM which is about
96 DPI. 96 DPI is the resolution of the web browser; this setting
works best when using the servlet or when creating images for the
web browser. More information about setting the resolution and x
dimension is provided in our
Java
Resolution KB Article.
|
|
RotationAngle
|
ROTATE
|
0
|
Indicates the angle of the barcode. Valid values are 0 (normal),
90 (vertical), 180 (inverted) and 270 (inverted vertical).
|
|
Font
|
TEXT_FONT
|
Arial
|
The font used to display the human readable code. To change the
font in the class library, use the following syntax:
Font newFont = new
Font("Arial",Font.PLAIN,30);
bc.setFont(newFont);
and to change the font in the applet or servlet, use this syntax:
&TEXT_FONT=ARIAL|BOLD|12
|
|
Size
|
WIDTH, HEIGHT
|
Null
|
Sets the size in pixels of the barcode image. If the size is set
manually, autoSize must be turned off. When using the applet
and servlet, autoSize is automatically set to false if the HEIGHT
and WIDTH are manually specified.
|
|
ProcessTilde
|
PT
|
TRUE
|
If true, (or "Y" when using the applet or servlet) the tilde (~)
will be processed as explained here. The
default is True.
|
|
ShowText
|
ST
|
Y
|
If this value is true, the human readable text will be displayed
with the barcode. The applet and servlet convert "Y" to true and "N"
to false.
|
|
TextMarginCM
|
TEXT_MARGIN
|
0.3
|
The amount of space between the barcode and the human readable
text.
|
|
TopMarginCM
|
TOP_MARGIN
|
.2
|
The top margin of the barcode (also know as the quiet zone).
|
|
UPCESystem
|
UPCE_SYSTEM
|
0
|
The encoding system to be used for UPC-E compression, valid
values are 0 and 1. The default is 0.
|
|
whiteBarIncrease
|
WHITEBAR_INCREASE
|
0
|
The percentage of the XDimension to increase the white bars.
Valid options are 0-99.
|
|
XDimensionCM
|
X
|
.03
|
This setting adjusts the width in centimeters of narrow bars,
which also adjusts the entire width of the barcode. More information
about setting the resolution and x dimension is provided in our
Java
Barcode Resolution KB Article.
|
| Aztec
Java Barcode Properties: |
|
Properties and Methods (Refer to the
index of fields and methods for more detailed information.
Common properties such as X Dimension, Color and Margin are the same
as noted in the Linear Properties.) |
| Class Properties |
Applet
|
Default |
Comments |
| ErrorCorrectionLevel |
ECL |
0 |
The Reed Solomon error correction
level encoded in the symbol, specified as a value from 1 to 99. More
error correction creates a larger symbol that can withstand more
damage. The default setting of 0 performs automatic
selection, which is usually a value of 23. |
| MessageAppend |
MA |
1 |
Specifies the message appended across
multiple symbols. Only valid if NumberOfSymbols is greater than 1. |
| NumberOfSymbols |
NS |
1 |
Invokes Message Append across
symbols. |
| ProcessTilde |
PT |
FALSE |
If true (or "Y" when using the
applet for servlet) the tilde (~) will be processed. More
information about the tilde is explained. |
| ReaderInitialization |
RI |
FALSE |
Adds the reader initialization
symbol to the barcode for older scanners, which require it. |
|
Properties and Methods (Refer to the
index of fields and methods for more detailed information.
Common properties such as X Dimension, Color and Margin are the same
as noted in the Linear Properties.) |
| Class Properties |
Applet
|
Default
|
Comments |
| EncodingMode |
MODE |
ASCII |
The encoding mode; valid values are E_ASCII, E_C40,
E_TEXT or E_BASE256. When using the applet or servlet, exclude the
"E_"; for example, use TEXT instead of E_TEXT. When using the
JavaBean, use the "setEncodingMode" field and enter the appropriate
number for the desired mode:
- 0=E_ASCII (default)
- 1=E_C40
- 2=E_TEXT
- 3=E_BASE256
More information about encoding modes.
|
| (see
class barCodeEncoder in the encoderDoc folder of the package) |
FORMAT |
JPEG |
Determines
the format of the image when using the servlet or saving a barcode
image to a file. Valid values are GIF and JPEG. The GIF files generated
are typically 4 to 20 times smaller in size than the JPEG files. |
| PreferredFormat |
PFMT |
-1 |
Sets the preferred format
represented by a number; valid values are from 0 (10X10) to 23
(144X144) and from 24 (8X18) to 29 (16X48); The default value is -1
which sets this to automatic; more information about preferred format. When using the
applet or servlet, enter "C" and the format all uppercase. For example,
for 16 x 48 enter C16X48. If the format chosen is too small for the
data to be encoded, an appropriate square symbol will be selected. |
| ProcessTilde |
PT |
FALSE |
If
true (or "Y" when using the applet for servlet) the tilde (~) will be
processed. More information about the tilde
is explained. |
|
PDF417 Java Barcode Properties:
|
|
Properties
and Methods
(Refer to the
index
of fields and methods for more detailed information. Common
properties such as X Dimension, Color and Margin are the same as noted
in the Linear Properties.)
|
|
Class
Properties
|
Applet
|
Default
|
Comments
|
|
binaryCode
|
na
|
null
|
The data (as a byte array) to be encoded in the
barcode
|
|
(see class barCodeEncoder in the encoderDoc folder
of the package)
|
FORMAT
|
JPEG
|
Determines the format of the image when using the
servlet or saving a barcode image to a file. Valid values are GIF and
JPEG. The GIF files generated are typically 4 to 20 times smaller in
size than the JPEG files.
|
|
macroPDFEnable
|
na
|
FALSE
|
Determines if the barcode being created will be
part of a MacroPDF barcode.
|
|
macroPDFFileID
|
na
|
0
|
Sets the id of the barcode in a sequence of
barcodes for MacroPDF. Each MacroPDF barcode in a sequence must have
the same File ID so the reader can reassemble them correctly.
|
|
macroPDFLastSegment
|
na
|
FALSE
|
Determines if this barcode in a sequence of
MacroPDF barcodes is the final segment.
|
|
macroPDFSegmentIndex
|
na
|
0
|
Sets the index number of this barcode in a
sequence of MacroPDF barcodes. Each barcode in the sequence
must have a unique segment index. Readers will reassemble the barcode
in the order of the segment index.
|
|
PDFColumns
|
COL
|
5
|
The number of columns in the symbol. Increasing
this value creates a wider symbol that is less in height. Use
this property to size the symbol.
|
|
PDFErrorCorrection
|
ECL
|
2
|
The error correction level for PDF417. The range
is from 0 to 8.
|
|
PDFMode
|
MODE
|
BINARY
|
In the applet and servlet, the PDF417 mode can be
set to NUMERIC, TEXT or BINARY. In the class library and JavaBean, the
PDF417 mode can be set to one of the following numbers; 0=BINARY,
1=TEXT or 2=NUMERIC.
|
|
PDFRows
|
ROWS
|
0
|
The number of rows for PDF417. It is not
recommended to set this number because the number of rows is
automatically generated and an incorrect number can cause the symbol to
be too large. Please set the PDF Columns instead to adjust the size.
|
|
Truncated
|
TRN
|
FALSE
|
A setting of true will enable truncation. A
truncated PDF417 symbol is more area efficient than normal PDF417. By
selecting this option, the right hand side of the PDF417 is removed or
truncated. This option should only be used in clean environments since
it is less resilient to damage. The servlet and applet converts "Y" to
true and "N" to false.
|
|
XtoYRatio
|
XYR
|
3
|
The X multiple height of individual cells. This is
usually set between 3 and 5. A higher number creates an easier to read,
taller symbol.
|
|
Properties
and Methods
(Refer to the
index
of fields and methods for more detailed information. Common
properties are the same as noted in the Linear
Properties.)
|
|
Class
Properties
|
Applet
|
Default
|
Comments
|
|
Data
|
DATA
|
JPEG
|
The data to be encoded in the barcode. For most
purposes, such as creating symbols for UPS, data should be
pre-formatted into a single string as described in the
MaxiCode
FAQ.
|
|
Mode
|
MODE
|
2
|
The encoding mode. A valid value is a number from
2 to 6.
|
|
Resolution
|
RESOLUTION
|
200
|
The resolution used to create the image in DPI;
Default is 200 DPI, which is the minimum required for MaxiCode.
|
|
ProcessTilde
|
PT
|
TRUE
|
If true, (or "Y" when using the applet for servlet)
the tilde (~) will be processed. More information about the
tilde is explained.
|
Free product support may be obtained by reviewing the knowledgebase
articles that are documented below and by searching resolved
public
help desk issues. Priority phone, e-mail and help desk
support
is provided up to 30 days after purchase. Additional priority phone,
e-mail and help desk
support
may be obtained if a
Priority
Support and Upgrade Subscription is active.
© Copyright 2000-2009
IDAutomation.com, Inc., All Rights Reserved.
Legal
Notices.
|
Over 70% of Fortune 100 companies
use IDAutomation's products to automate their businesses.
|
|