|
||||||||
|
||||||||
|
||||||||
Home: Products: Barcode Components: Java Barcode Package: User Manual: | ||||||||
A license is required for each
computer this software is installed on; |
Properties of the Linear BarCode class: |
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 (Please refer to the index of fields and methods for more detailed information) | ||||
Class Library | JavaBean | Applet & Servlet | Default Value | Comments |
autoSize | AutoSize | see comments | 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). When using the applet or servlet, autoSize will automatically be set to false 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 and setting autoSize to false. |
barType | 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 |
backColor | 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). |
barColor | 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 | BarHeightCM | BAR_HEIGHT | 1 | The height of the bars in CM, which also adjusts the entire height of the barcode. |
bearerBarHori | bearerBarHorizontal | BEARERBAR_HORIZONTAL | 0 | The size of the horizontal bearer bars. Valid values are 0-10 which are a multiple of X. |
bearerBarVert | bearerBarVertical | BEARERBAR_VERTICAL | 0 | The size of the vertical bearer bars. Valid values are 0-10 which are a multiple of X. |
characterGrouping | 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 | CODABARStartChar | CODABAR_START | A | Start character for CODABAR. Valid values are "A", "B", "C" or "D". |
CODABARStopChar | CODABARStopChar | CODABAR_STOP | B | Stop character for CODABAR. Valid values are "A", "B", "C" or "D". |
code | 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 | 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 | 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. |
fontColor | 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). |
barCodeEncoder format (see example) | (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 | LeftMarginCM | LEFT_MARGIN | .3 | The left margin in CM. This may need to be increased for UPC and EAN barcode types. |
N | 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. |
resolution | 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. |
rotate | RotationAngle | ROTATE | 0 | Indicates the angle of the barcode. Valid values are 0 (normal), 90 (vertical), 180 (inverted) and 270 (inverted vertical). |
setFont | 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 |
setSize | 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. |
setProcessTilde | 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 | 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 | TextMarginCM | TEXT_MARGIN | 0.3 | The amount of space between the barcode and the human readable text. |
topMarginCM | TopMarginCM | TOP_MARGIN | .2 | The top margin of the barcode (also know as the quiet zone). |
UPCESystem | 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 | whiteBarIncrease | WHITEBAR_INCREASE | 0 | The percentage of the XDimension to increase the white bars. Valid options are 0-99. |
X | 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 Resolution KB Article. |
JPEG or GIF file encoder example |
High quality GIF and JPEG images may be easily created with the encoder. Before creating a JPEG file with the Java Package, the following requirements must be met:
Install JDK 1.2 or above or verify that JDK 1.2
or above is installed on the server. The encoder requires Java 2 or JDK
1.2 or above to create the JPEG files used by the servlet.
Special requirements for Linux and UNIX servers:
How to create a JPEG or GIF image file:
This 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="123456789";
bc.barType=bc.CODE39;
barCodeEncoder bce = new barCodeEncoder(bc, "JPEG", "newfile.jpeg");
// To create a GIF instead, use
// barCodeEncoder bce = new barCodeEncoder(bc, "GIF", "newfile.gif");
System.exit(0);
}
}
Additional examples are provided in the package download for each symbology.
Java Barcode Servlet Implementation and Example |
IDAutomation's Java Servlets may be used to add server-side barcode generation capability to a dedicated web server. IDAutomation's Servlet is compatible with all browsers and is easy to embed in HTML as an image with the <IMG> tag.
Servlet Implementation:
IDAutomation offers a tutorial for servlet implementation with Apache Tomcat. Additional examples are provided below.
Example Using JSDK:
Install JDK 1.2 or above or verify that JDK 1.2
or above is installed on the server. The encoder requires Java 2 or JDK
1.2 or above to create the JPEG files used by the servlet.
Special requirements for Linux and Unix servers:
Servlet Implementation Using ServletExec ISAPI on Windows® Server:
Inserting barcodes into HTML - after the servlet is working:
The image that is created defaults to the screen
resolution of 96 DPI and may be compressed if necessary to obtain
smaller X dimensions or precision. Because of the screen’s resolution, the X
dimension can only be adjusted within increments of .03cm. For
example, if an X dimension of .015 is needed, the image on the web
page must be compressed by 50%. The following HTML tag reduces the
image by 50%; it will not look correct on the screen but it will print
correctly.
<IMG height=40 alt="Barcode Image" src="http://javabarcoding.com/servlet/lin?HEIGHT=80&WIDTH=160&BARCODE=12345678"
width=80>
Creating secure servlets:
Other methods of servlet operation can be accomplished by developers that modify the servlet source code provided. This may be necessary to make sure 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.
java.awt.Image object Implementation |
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 );
Barcode Applet Implementation |
An applet can easily display barcodes in HTML pages. However, applets do not always work on all web browsers, more about applet problems....
Example of how to use the applet in HTML:
<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 can 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();
An example of using the applet is provided in the ZIP file download. The file is named "LinearAppletTest.html".
Applet Pre-Loading
The time it takes to create barcodes on web pages using applets can 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 - even over slow dial-up lines. 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>
Barcodes Types Supported in the Linear Package |
The following is a short description of some of the barcode types:
PDF417 Properties: |
This section explains the main properties, methods and configuration parameters of the PDF417 package. For a more complete list, review the index of fields and methods. Specific implementation examples and code may be found within the 2D package. Additional information about this symbology is provided in the PDF417 Symbology FAQ.
Properties and Methods (Please refer to the index of fields and methods for more detailed information) | ||||
Class Library | JavaBean | Applet & Servlet | Default Value | Comments |
binaryCode | na | 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 | macroPDFEnable | na | FALSE | Determines if the barcode being created will be part of a MacroPDF barcode. |
MacroPDFFileID | 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 | macroPDFLastSegment | na | FALSE | Determines if this barcode in a sequence of MacroPDF barcodes is the final segment. |
MacroPDFSegmentIndex | 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 | 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. |
PDFECLevel | PDFErrorCorrection | ECL | 2 | The error correction level for PDF417. The range is from 0 to 8. |
PDFMode | 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 | 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 | 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 immune to damage. The servlet and applet converts "Y" to true and "N" to false. |
XtoYRatio | 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. |
DataMatrix Properties: |
This section explains the main properties, methods and configuration parameters of the package. For a more complete list, review the index of fields and methods. Specific implementation examples and code may be found within the 2D package. Additional information about this symbology is provided in the DataMatrix Symbology FAQ.
Properties and Methods (Please refer to the index of fields and methods for more detailed information) | ||||
Class Library | JavaBean | Applet & Servlet | Default Value | Comments |
encoding | 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:
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 | 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 | 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. |
MaxiCode Properties: |
This section explains the main configuration parameters of the MaxiCode class. For a more complete list, review the index of fields and methods. Specific implementation examples and code may be found within the 2D package. Additional information about this symbology is provided in the Maxicode Symbology FAQ.
Properties and Methods (Please refer to the index of fields and methods for more detailed information) | ||||
Class Library | JavaBean | Applet & Servlet | Default Value | Comments |
data | 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 | MODE | 2 | The encoding mode. A valid value is a number from 2 to 6. |
setResolution | Resolution | RESOLUTION | 200 | The resolution used to create the image in DPI; Default is 200 DPI, which is the minimum required for MaxiCode. |
processTilde | 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. |
|
For more information about the various barcode symbologies, please visit the IDAutomation.com Support Site and select the symbology from the list of symbology FAQs.
To stay informed about software updates or new
products, subscribe to
IDAutomation's Newsletter or
RSS Feed.
|
Product Quick Links: [Barcode Fonts | Font Tools | Components | Label Software | Scanners | Printers | RFID] |
Copyright © 2000-2006 IDAutomation.com, Inc. IDAutomation and BizFonts are registered trademarks of IDAutomation.com, Inc. All other trademarks mentioned are the property of their respective owners.
Over 70% of Fortune 100 companies use IDAutomation's products to automate their businesses. |