RSS and EAN-UCC Composite Barcodes for the Java[TM] Platform


Introduction

This package can be used in java applications, applets and web server for creating RSS and EAN-UCC composite barcodes. The supported symbologies are:

  • RSS. The EAN.UCC Reduced Space Symbology (RSS) family contains three linear symbologies:
    • RSS-14 encodes a 14-digit EAN.UCC item identification. This symbology has 4 formats , regular, truncated, stacked and omni-directional stacked.
    • RSS Limited encodes a 14-digit EAN.UCC item identification with Indicator digits of zero or one in a linear symbol for use on small items.
    • RSS Expanded encodes EAN.UCC item identification plus supplementary AI element strings such as weight and “best before” date in a linear symbol. This symbology has 2 formats, regular and stacked.
  • EAN-UCC Composite: these symbols are intended for encoding identification numbers and data supplementary to the identification. Each barcode consists of a linear component and a multi-row 2D Composite Component. The 2D Composite Component is printed above the linear component. The linear component can be any EAN-UCC or RSS linear symbol. The 2D component can be only of the following:
    • CC-A, encodes up to up to 56 digits.
    • CC-B, encodes up to up to 338 digits.
    • CC-C, up to 2 361 digits.

     

    Supported combinations of linear and multi-row symbols are:

    • UPC-A and EAN-13 with a CC-A or CC-B 2D component (4 columns).
    • EAN8 with a CC-A or CC-B 2D component (3 columns).
    • UPCE with a CC-A or CC-B 2D component (2 columns).
    • EAN128 with a CC-A or CC-B 2D component (4 columns).
    • EAN128 with a CC-C component.
    • RSS-14 with a CC-A or CC-B 2D component (4 columns).
    • RSS-14 Stacked with a CC-A or CC-B 2D component (2 columns).
    • RSS-14 Stacked Omni-directional with a CC-A or CC-B 2D component (2 columns).
    • RSS Limited with a CC-A or CC-B 2D component (3 columns).
    • RSS Expanded with a CC-A or CC-B 2D component (4 columns).
    • RSS Expanded Stacked with a CC-A or CC-B 2D component (4 columns).

Java API

This section explains how to use the classes in your java application. You will find a complete description of all classes and methods in the Javadoc files.

In order to create a barcode you must create an instance of one of the following classes:

  • com.java4less.rss.BarCode: use this class to create EAN8, EAN13, EAN128, UPCE or UPCA symbols. Use the setSymbology() method to select the symbology to use.
  • com.java4less.rss.RSS: use this class to create RSS14, RSS stacked, RSS truncated or RSS stacked omni-directional symbols. Use the setRSSFormat() method to select the symbology to use.
  • com.java4less.rss.RSSLimited: use this class to create RSS Limited symbols.
  • com.java4less.rss.RSSExpanded : use this class to create RSS Expanded or Expanded Stacked symbols. Use the setRSSFormat() method to select the stacked or non-stacked format.

The following example creates a EAN128 barcode and exports it to a jpg file.

BarCode r=new BarCode();
r.setSymbology(BarCode.EAN128);
r.setCode("0193812345678901");
r.setHumanReadableCode("(01)93812345678901");
r.setSize(300,300);
new ImageEncoder(r,"JPEG","c:\\barcode.jpg");

If you want to create a composity symbols you must set the value for the 2D component using the setSecondaryCode() method. For example:


RSS r=new RSS();
r.setCode("0341234567890"); // Note: do not pass the 01 application identifier to RSS or RSSLimited classes.
r.setSecondaryCode("17010200"); // this forces the 2D component to be created.
r.setRSSFormat(r.FORMAT_STACKED);
r.setSize(300,300);
new ImageEncoder(r,"JPEG","c:\\barcode.jpg");


Note that you should not pass the 01 application identifier nor the checksum character in the setCode() method of the RSS or RSSLimited classes. You must however include all application identifiers for EAN128 and RSS Expanded symbols.


All linear symbols (except EAN128) can be associated with a CC-A or CC-B 2D component. The software will automatically select the correct component depending on the amount of data you need to encode.

EAN128 can be painted with a CC-A/B component or a CC-C component. In this case you must select the desired symbology using the setEAN128WithCCC() method. If you select CC-C you must also set the number of columns using setCCCColumns() (the default value is 4):

BarCode r=new BarCode();
r.setSymbology(r.EAN128);
r.setCode("0193812345678901");
r.setHumanReadableCode("(01)93812345678901");
// create a composite barcode
r.setEAN128WithCCC(true);
r.setSecondaryCode("10ABCD123456#4103898765432108");
r.setSize(300,300);
new ImageEncoder(r,"JPEG","c:\\barcode.jpg");

 

How to create a gif, png or jpg file.

You can also export the barcode to a gif,png or a jpeg file. In order to do this you must use the following code:

    import com.java4less.rbarcode.*;

    bc=new BarCode();
    bc.setSize(400,200); // important, set size
    ....
    new ImageCodeEncoder(bc,"GIF","file.gif");
    new ImageCodeEncoder(bc,"PNG","file.png");
    new ImageCodeEncoder(bc,"JPEG","file.jpg");

note that:

How to create the barcode in a java.awt.Image object

The following code illustrates how you can paint 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 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.

com.java4less.rss.BCApplet

You can use BCApplet to display barcodes in your HTML pages. If you are not familiar with Applets you will find a number of tutorial on the internet, for example:

The available parameters for the applet are:

  • CODE_TYPE: Use this parameter to select the symbology. The value must be one of the following: EAN8, EAN13, EAN128 , UPCE, UPCA, RSS14, RSSLIMITED or RSSEXPANDED.
  • RSS_FORMAT: Use this parameter to select the format of RSS14 or RSS expanded symbols. The accepted values are: FORMAT_REGULAR, FORMAT_TRUNCATED, FORMAT_STACKED, FORMAT_STACKED_OMNIDIRECTIONAL, FORMAT_EXPANDED, FORMAT_EXPANDED_STACKED.
  • EAN128_CCC (Y or N): selects the 2D component to be painted together with EAN128 symbols. Use Y to select CC-C and N to select CC-A/B.
  • CCC_COLUMNS: number of columns of the CC-C component (only used if EAN128_CCC=Y).
  • SECONDARY_CODE: value to be encoded in the 2D Component (use # as FNC1 character).
  • PRIMARY_CODE: value to be encoded in the linear component (use # as FNC1 character).
  • READABLE_CODE: Value to be painted (as human readable text) below the linear code. If empty the package will calculate it (except for EAN128).
  • SUPPLEMENT_SEPARATION: separation in pixels between the symbol and the supplement.
  • SUPPLEMENT_HEIGHT: height of the bars of the supplement.
  • SUPPLEMENT: Type of EAN supplement 2 or 5
  • ROTATE: Indicates how the barcode should be painted (vertica, horizontal ...). Valid values are 0 (normal), 90 (vertical),180 (inverted) and 270 (inverted vertical).
  • X: width of the bars in pixels
  • LEFT_MARGIN: left margin in pixels.
  • TOP_MARGIN: top margin in pixels.
  • BAR_COLOR: color of the bars.
  • PROCESS_TILDE. If Y, the ~ character will be processed as follows:
    • ~dNNN stands for the character whose ascii code is NNN. For example ~d065 stands for 'A'.
    • ~~ stands for ~
  • FONT_COLOR: color of the font used to display the code.
  • BACK_COLOR: back color of the barcode.
  • GUARDBARS: indicates if guardbars will be height than other bars. Only for EAN and UPC.
  • UPCE_SYSTEM: encoding system to be used for UPCE, valid values are 0 and 1 (default).
  • TEXT_FONT: font used to display the human readable code. Set this value to NULL if you want to suppress the text.
  • H: 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.
  • BAR_HEIGHT: instead of using the H paramneter you can use this parameter to specify the height of the bars of the linear component (in pixels):
  • BAR_HEIGHT2D: height in pixels of the rows of the 2D Component.

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 = "com.java4less.rss.BCApplet.class"
ARCHIVE1 = "rrss.jar"
NAME = "TestApplet"
WIDTH = 300
HEIGHT = 250
HSPACE = 0
VSPACE = 0
ALIGN = middle
><PARAM NAME = "PRIMARY_CODE" VALUE = "0361234567890">
<PARAM NAME = "CODE_TYPE" VALUE = "RSS14">
<PARAM NAME = "LEFT_MARGIN" VALUE = "10">
<PARAM NAME = "TOP_MARGIN" VALUE = "10">
<PARAM NAME = "TEXT_FONT" VALUE = "ARIAL|BOLD|11">
</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('PRIMARY_CODE','new value');
    TestApplet.refresh();

There in an example of the use of javascript in the AppletExample.html file.

The servlet

RBarcodeServlet will allow you to use RBarcode as Servlet without any Java programming. The servlet has the advantage that the java classes must not be downloaded to the client's browser. This means your barcode will be displayed faster. It has however the disadvantage that you need to have a web server able to execute servlets.

In the case of servlets, the barcodes are created in the server and the output in PNG, GIF or JPEG format is sent to the browser. This also means that you can use RBarcode to in browsers that do not support Java.

You can very easily use RBarCodeServlet. The parameters are the same as those for the applet. You can send the parameters to the Servlet using the POST or GET methods. Furthermore there are some additional parameters:

  • WIDTH: width in pixels of the output image. (default is 500).
  • HEIGHT: height in pixels of the output image. (default is 500).
  • FORMAT: format of output image, "gif", "png" or "jpeg". (default is JPEG).

Note that

Example of installation on Tomcat 5.0:

  1. create directory rss in the webapps directory (i.e. tomcatDirectory\webapps\rss)
  2. copy the rrss.jar to tomcatDirectory\webapps\rss\WEB-INF\lib
  3. copy the web.xml file from any other project to tomcatDirectory\webapps\rss\WEB-INF\web.xml. Add the following lines to the file:

    <servlet>
    <servlet-name>RSSServlet</servlet-name>
    <servlet-class>com.java4less.rss.RBarCodeServlet</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>RSSServlet</servlet-name>
    <url-pattern>/servlet/RSSServlet</url-pattern>
    </servlet-mapping>

  4. Start the server (tomcatDirectory\bin\startup.bat) an test the servlet entering the following address and parameters in your browser:

    http://localhost:8080/rss/servlet/RSSServlet?DEBUG=ON&PRIMARY_CODE=0361234567890&LEFT_MARGIN=20&CODE_TYPE=RSS14&WIDTH=300&HEIGHT=300

    http://localhost:8080/rss/servlet/RSSServlet?DEBUG=ON&PRIMARY_CODE=
    0361234567890&LEFT_MARGIN=20&CODE_TYPE=RSS14&SECONDARY_CODE=1234

Java, JSP, JDBC, JDK and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. J4L Components is independent of Sun Microsystems, Inc.