产生条形码

来源:互联网 发布:人员管理系统 php 编辑:程序博客网 时间:2024/05/19 23:00

http://java4less.com/

http://java4less.com/barcodes/barcodes.php?info=guide#intro

RBarcode for the Java[TM] Platform, User Guide

Copyright J4L (http://www.java4less.com) 2008

  • Introduction
    • Java code
      • Use in frames and Panels
      • How to create jpeg, gif or png files
      • How to paint on external Graphics objects
    • Servlet and JSP
    • Applet
  • Barcodes 1D
    • Introduction
    • Parameters and properties of the Java class
  • PDF 417 and Macro PDF 417
    • Introduction
    • Parameters and properties of the Java class
  • Datamatrix
    • Introduction
    • Parameters and properties of the Java class
  • QRCode, RSS, Aztec code and Maxicode
  • Jasper Report and iReport integration
  • Barcoding Web Services
  • FOP plugin (PDF generation)
  • JavaDoc files: open the index.html file in the javadoc subdirectory.
  • Questions?

 

Introduction

RBarcode is a java package that creates 1D and 2D barcodes. The package can be used in several situations:

  • In Java applications
  • In web applications, as servlet or JSP pages
  • In non Java web application as applet.

 

Java code

The 3 main classes of RBarcode are:

  • com.java4less.rbarcode.BarCode: for 1D symbologies
  • com.java4less.rbarcode.BarCode2D: for PDF417 and Macro PDF417 symbologies
  • com.java4less.rdatamatrix.DataMatrix: for Datamatrix symbology

These classes can be used to:

  • display barcodes in your forms or panels
  • create image files (png, jpeg or gif)
  • or paint the barcodes in external Graphic objects

 

Use in frames and panels

Since the barcode classes are a subclass from java.awt.Canvas you can add them to any container like panels. The following example is a very simple java form that displays a barcode:

import javax.swing.JFrame;
import com.java4less.rbarcode.BarCode;

public class BarcodeForm extends JFrame {
BarCode bc = new BarCode();

public BarcodeForm() {
this.getContentPane().setLayout(null);
bc.setBounds(new Rectangle(10, 10, 328, 253));
this.getContentPane().add(bc, null);
this.setSize( 348, 273);

// settings for the barcode
bc.code="1234";
bc.checkCharacter=true;
}

public static void main(String[] args) {
BarcodeForm barcodeForm = new BarcodeForm();
barcodeForm.show();
}

}

 

How to create a gif, png or jpg files.

You can also export the barcode to a gif,png or 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 BarCodeEncoder(bc,"GIF","file.gif");
    new BarCodeEncoder(bc,"PNG","file.png");
    new BarCodeEncoder(bc,"JPEG","file.jpg");

note that:

  • If you want to create gif files, the gif encoder must previously be downloaded and included in your classpath: http://www.acme.com
  • If you want to create png files, the png encoder must previously be downloaded and included in your classpath: http://209.51.137.74/pngencoder-1.0.jar
  • In order to use the JPEG encoder you just nee Java 1.2 or later however gif or png produce clearer images.

 

How to paint on external Graphics objects

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 );

 

Servlet and JSP

The class com.java4less.rbarcode.RBarCodeServlet will allow you to use RBarcode as Servlet without any Java programming. 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. You can very easily use RBarCodeServlet. The servler has 2 types of parameters:

  • Service parameters: these are parameters required by the servlet:
    • 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).
  • Data parameters. These are the parameters required to create the barcode. The parameters depend on the type of barcode you want to create, please look at the section Parameters in RBarcode1D, PDF417 and Datamatrix. There are however 2 common and very important parametes:
    • BARCODE: this is the value that should ne encoded
    • CODE_TYPE: used to select the barcoding symbology

note that:

  • If you want to create gif files, the gif encoder must previously be downloaded and included in your classpath: http://www.acme.com
  • If you want to create png files, the png encoder must previously be downloaded and included in your classpath: http://209.51.137.74/pngencoder-1.0.jar
  • In order to use the JPEG encoder you just nee Java 1.2 or later however gif or png produce clearer images.

Example; how to set up the servlet in Tomcat 5 (the setup is almost the same in any server):
In order to run the servlet using Tomcat 5 you can follow these steps:

  1. create a new empty directory for rbarcode in Tomcat: "tomcatdirectory/webapps/rbarcode"
  2. copy the content of the directory "example_servlet_jsp/war" to "tomcatdirectory/webapps/rbarcode"
  3. start Tomcat
  4. Open the following URL in you browser:

    http://localhost:8080/rbarcode/BarcodeServlet?BARCODE=123456789012&CHECK_CHAR=Y&CODE_TYPE=EAN13


    or if you want to change the size or format of the image add the service parameters:

    http://localhost:8080/rbarcode/BarcodeServlet?BARCODE=123456789012&WIDTH=50&HEIGHT=50&CHECK_CHAR=Y&CODE_TYPE=EAN13&CHECK_CHAR=Y&FORMAT=gif&WIDTH=600&HEIGHT=600

Note: if you want to use the PNG or the GIF encoder you must copy the jar file to "tomcatdirectory/webapps/rbarcode/WEB-INF/lib"

If you have any problems running the servlet check that the servlet is actually beeing executed, look in the java console or in the servlets logs if there are messages written by the servlet.

In most situations you will use the servlet link inside the IMG tag. In this way you can embed the image in your HTML page. For example:

<HTML>
<BODY bgColor=#ffffff>
This is your Barcode:
<IMG height=500 width=500 src="
http://localhost:8080/rbarcode/BarcodeServlet?BARCODE=123456789012&CHECK_CHAR=Y&CODE_TYPE=EAN13" >
</BODY>
</HTML>

Note that you can use the size attributes height and width in order to change the size of the displayed images and also increase the printing resolution. Browsers normally print at 96 dpi, however if you need to print using a higher resolution you can do this:

  1. create an image which is , for example 300 x 300 (using the HEIGH and WIDTH parameters of the servlet)
  2. use the IMG tag and set the attributes height=150 and width=150
  3. When you print the web page, the image will be 300 x 300 but it will take the space of a 150 x 150 image. In other words , you will be printing at about 180 dpi (instead of 96 dpi).

The product can also be used in JSP environment. The following JSP page creates the HTML output for displaying the barcode using the servlet:

<%String encode="jpeg";
String value="123456";
String type="BAR39";
String servletUrl="BarcodeServlet?BARCODE="+value+"&CHECK_CHAR=Y&CODE_TYPE="+type;
response.setContentType("text/html");
response.setDateHeader ("Expires",0);


// get output stream
java.io.PrintWriter outb=response.getWriter();

// generate html
outb.print("<HTML>");
outb.print("<BODY bgColor=#ffffff>");
outb.print("This is your Barcode:<br><br>");
outb.print("<IMG src='"+servletUrl+"' >");
outb.print("</BODY>");
outb.print("</HTML>");

%>

If you do not want to use the servlet you can also create a JSP page that generates the barcode image like this:

<%
int w=400;
int h=200;
response.setContentType("image/jpeg");
response.setDateHeader ("Expires",0);
response.setHeader ("Pragma", "no-cache");
response.setHeader ("Cache-Control", "no-cache");
response.setDateHeader ("Expires",0);

// get output
javax.servlet.ServletOutputStream outb=response.getOutputStream();
//create image and encoder
com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(outb );
java.awt.image.BufferedImage barImage=new java.awt.image.BufferedImage(w,h,java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D barGraphics=barImage.createGraphics();


// create barcode
com.java4less.rbarcode.BarCode bc=new com.java4less.rbarcode.BarCode();
bc.setSize(w,h);
bc.barType=com.java4less.rbarcode.BarCode.BAR39;
bc.code="123456";
bc.checkCharacter=true;

// work with pixels
bc.X=1;
bc.resolution=1;
bc.topMarginCM=30;
bc.leftMarginCM=30;

bc.setSize(w,h);

// paint and encode
bc.paint(barGraphics);
encoder.encode( barImage );

%>

Note that is you use the servlet in a Linux or Unix computer you might need to enabled the Java Headless mode if you get X11 errors because of a missing display.

 

Applet

Applets are small java programs that run inside your browser, this means they must be first downloaded from the server so that they can be executed by your browser.In order to run applets your browser must be Java enabled. RBarcode will run in old browsers also since it also runs with Java version 1.1 or later.


Applets are downloaded and executed when the brower finds the <APPLET> tag inside the HTML code. The tag has the following structure:

<APPLET
CODE=...
CODEBASE=..
ARCHIVE=.
NAME=...
WIDTH=...
HEIGHT

>
<PARAM NAME = "appletParameter1" VALUE = "value1">
<PARAM NAME = "appletParameter2" VALUE = "value2">
<PARAM NAME = "appletParameter3" VALUE = "value3">

.....
< /APPLET>

The green code is used to configurate the applet (size, name, Java class to be executed), and the blue code is used to pass parameters to the applet. These are the parameters you use to define the barcode.

The values for the Applet attributes are:

  • CODE: this is the Java class. It can be:
    • com.java4less.rbarcode.BCApplet.class for 1D barcodes
    • com.java4less.rdatamatrix.BCAppletDM.class for Datamatrix
    • com.java4less.rbarcode.BCApplet2D.class for PDF 417
  • ARCHIVE: it must be rbarcode.jar
  • CODEBASE: this is the directory where rbarcode.jar can be found

The Barcdode 1D applet can be executed with as litte code as:

<HTML>
<BODY>
<APPLET
CODEBASE = "./"
CODE = "com.java4less.rbarcode.BCApplet.class"
NAME = "TestApplet"
ARCHIVE = "rbarcode.jar"
WIDTH = 500
HEIGHT = 500
ALIGN = middle
>
<PARAM NAME = "BARCODE" VALUE = "123459">
<PARAM NAME = "TYPE_CODE" VALUE = "BAR39">
</APPLET>
</BODY>
</HTML>

In order to run this applet you must:

  1. copy this code to a file: Applet.html
  2. copy rbarcode.jar to the same directory
  3. Open Applet.html with your browser

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"

Apart from the BARCODE and CODE_TYPE parameters, there are many other you can use for the configuration of the barcode. The parameters depend on the type of barcode you want to create, please look at the section Parameters in RBarcode1D, PDF417 and Datamatrix.

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 1D

Introduction

The following is a short description of some of the supported 1D barcode symbologies:

  • 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.
  • EAN128. It is a special type of CODE128 barcode which starts with a FNC1 character.
  • The initial FNC1 character will be added automatically but you can add additional FNC1 character (separators) in the barcode by using a space " " or a character 202.

  • 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).
  • Switchs between character sets A (upper case letters, digits and punctuation characters), B ( digits, upper case and lower case characters) and C (numeric) will happen automatically in order to minimize the length of the barcode. However you can force a character switch using the following characters in the input data: character 199 (for a switch to numeric character set C), character 201 (force a switch to character set A) and character 200 (force a switch to character set B).

  • 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 .

Parameters and properties of the Java class

This section lists the properties of the BarCode class and the equivalent parameter for the servlet or applet. Please look at the JavaDoc files for a update list of parameters.

  • barType (parameter CODE_TYPE in applet and servlet): 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, EAN128, POSTNET, UPCA and UPCE.
  • backColor (BACK_COLOR in applet and servlet): back color of the barcode.
  • barColor (BAR_COLOR in applet and servlet): color of the bars.
  • barHeightCM (BAR_HEIGHT in applet and servlet): height of the bars in CM. If this value is 0, it will be calculated using H.
  • CODABARStartChar (CODABAR_START in applet and servlet): Start character for CODABAR. Valid values are "A", "B", "C" or "D".
  • CODABARStopChar (CODABAR_STOP in applet and servlet): Stop character for CODABAR. Valid values are "A", "B", "C" or "D".
  • code (parameter BARCODE in applet and servlet): this is the value to be encoded.
  • code128set (parameter CODE128_SET in applet and servlet): set of charaters to be used in code128. Valid values are : A, B or C. RBarcode will automatically select the correct encoding mode (set A,B or C) according to the input data.

    If it encounters at least 4 digits in a sequence while in mode A or B, it will witch to mode C: for example "ASDCC80123". You can however also force a manual switch to mode C with ~d199 (note you must set processTilde=true) , for example ASDCC~d19980123.

    Switching from mode C to A/B also happens automatically but you can force it (not required) with ~d201 (C to A) or ~d200 (C to B). For example "ASDCC801234~d201AAA" is the same as "ASDCC801234AAA"

  • checkCharacter (CHECK_CHAR in applet and servlet): If true the software will calculate the check character automatically. The applet converts "Y" to true and "N" to false.
  • fontColor (FONT_COLOR in applet and servlet): color of the font used to display the code.
  • guardBars (GUARDS_BARS in applet and servlet): 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 in applet and servlet): 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 (POSTNET_TALL in applet and servlet): height (in CM) of PostNet's tall bar.
  • postnetHeightShortBar (POSTNET_SHORT in applet and servlet): height (in CM) of PostNet's short bar.
  • processTilde (PROCESS_TILDE): it true (or 'Y') , the tilde character in the input data will be processed as follows:

    ~dNNN represents the ascii character encoded by the 3 digits NNN. For example, ~d065 represents the character 'A'.

  • resolution: (RESOLUTION) number of pixels/Cm. If you set it to 1 then you will be working with units=pixels
  • rotate (ROTATE in applet and servlet): 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 in applet and servlet): relative height of the supplement's bars (only EAN and UPC). The default (0.8) means 80% of the normal bars.
  • supSeparationCM (SUPPLEMENT_SEPARATION in applet and servlet): separation between the code and the supplement (in CM). the default is 0.5 (only EAN and UPC).
  • textFont (TEXT_FONT in applet and servlet): font used to display the code.
  • topMarginCM (TOP_MARGIN in applet and servlet): top margin in CM.
  • UPCEANSupplement2 (SUPPLEMENT=2 in applet and servlet): indicates if the codes EAN and UPC will have a 2 digit's supplement.
  • UPCEANSupplement5 (SUPPLEMENT=5 in applet and servlet): indicates if the codes EAN and UPC will have a 5 digit's supplement.
  • UPCESystem (UPCE_SYSTEM in applet and servlet): encoding system to be used for UPCE, valid values are 0 and 1.
  • X (parameter X in applet and servlet):: width in centimeters of narrow bars. The default is 0.03.

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.

 

 

PDF 417 and Macro PDF 417

 

Introduction

PDF stands for “Portable Data File.” A two-dimensional symbology (2D), a single PDF417 symbol carries up to 1.1 kilobytes of machine-readable data in a space no larger than a standard bar code. And, unlike one-dimensional bar codes (1D), which are just a key linked to a database, PDF417 symbols contain the database itself. That means, you don't have to store an article number in the barcode but you can also store the name , the size , the color, the name of the manufacturer etc...

 

The basic characteristics are:

  • Each PDF417 symbol consists of a stack of vertically aligned rows with a minimum of 3 rows (maximum 90 rows). Each row can have 1 to 30 columns.
  • Three compaction modes:
    • Text Compaction mode allows all printable ASCII characters to be encoded (i.e. values 32 to126 and some additional control characters)
    • Byte Compaction mode allows any byte values to be encoded.
    • Numeric Compaction is a more efficient mode for encoding numeric data
  • The maximum capacity is (at error correction level 0):
    • Text Compaction mode: 1 850 characters
    • Byte Compaction mode: 1 108 characters
    • Numeric Compaction mode: 2 710 characters
  • Macro PDF417: this feature allows large amount of data to be encoded in a secuence of linked PDF417 symbols. Up to 99 999 different PDF417 symbols can be concatenated using this mechanism.
  • Compact PDF417: In clean environments, it is possible to reduce the size of the symbol by removing some non-data bars.Parameters

Parameters and properties of the Java class

This section lists the properties of the BarCode2D class and the equivalent parameter for the servlet or applet. Please look at the JavaDoc files for a update list of parameters.

Since it is an extension of RBarcode, therefore the some parameters are inherited from the BarCode class:

  • CODE_TYPE: must have the value PDF417.
  • BARCODE: text to encode.
  • BACK_COLOR.
  • BAR_COLOR
  • X
  • BAR_HEIGHT
  • RESOLUTION

The properties specific to PDF417 are:

  • PDFColumns (PDF_COLUMNS in applet and servlet): number of columns for PDF417 (the default is 10).
  • PDFECLevel (PDF_ECLEVEL in applet and servlet): error correction level for PDF417 (the default is 0).
  • PDFMode (PDF_COMPACTION in applet and servlet): PDF417 mode can be NUMERIC, TEXT or BINARY.
  • PDFRows (PDF_ROWS in applet and servlet): number of rows for PDF417 (optional).
  • PDFMaxRows (PDF_MAXROWS in applet and servlet): number of rows for PDF417 (optional).

Note: The Macro PDF properties are described in the JavaDoc files.

 

Datamatrix

 

Introduction

The package RDataMatrix contains an applet and a java class that will allow you to create data matrix (ECC200) barcodes for you java applications or HTML pages.

Data Matrix is a two-dimensional (2D) matrix symbology which is made up of square modules arranged within a perimeter finder pattern. It can encode up to 3116 characters from the entire 256 byte ASCII character set. The symbol consists of data regions which contain square modules set out in a regular array. Large ECC 200 symbols contain several regions. Each data region is delimited by a finder pattern, and this is surrounded on all four sides by a quiet zone border (margin).

ECC 200 symbols have an even number of rows and an even number of columns. Most of the symbols are square with sizes from 10 x 10 to 144 x 144. Some symbols however are rectangular with sizes from 8 x 18 to 16 x 48. All ECC 200 symbols can be recognized by the upper right corner module being light (binary 0).

ECC200 is the newest version of data matrix and supports advanced encoding error checking and correction algorithms (reed-solomon). This algorithms allow the recognition of barcodes that are up to 60% damaged.

The barcode supports two optional mechanisms:

  • The "Extended Channel Interpretation" (ECI) mechanism enables characters from other character sets (e.g. Arabic, Cyrillic ..) and other data interpretations or industry-specific requirements to be represented.
  • The "Structured append" allows files of data to be represented as a secuence of up to 16 Data Matrix symbols. The original data or file can be reconstructed regardless of the order of the symbols.

RDataMatrix supports:

  • All sizes and formats (from 10x10 till 144x144)
  • Ascii, text , C40 and Base256 (for binary data) encoding.
  • The "Extended Channel Interpretation and Structured append

Formats

RDataMatrix supports all data matrix formats. The following table contains the size , the capacity and the correction error features of each format

Size

Numeric Capacity

Alphanumeric capacity

Binary capacity

Max Correctable

Error/Erasure

10 x 10

6

3

1

2

12 x 121063314 x 14161065/716 x 162416106/9

18 x 18

36

25

16

7/11

20 x 204431209/15

22 x 22

60

43

28

10/17

24 x 24

72

52

34

12/21

26 x 26

88

64

42

14/25

32 x 32124916018/3336 x 361721278421/3940 x 4022816911224/4544 x 4428821414228/5348 x 4834825917234/6552 x 5240830420242/7864 x 6456041827856/10672 x 7273655036672/13280 x 8091268245496/18088 x 881152862574112/21296 x 9613921042694136/260104 x 10416321222814168/318120 x 120210015731048204/390132 x 132260819541302248/472144 x 144311623351556310/5908 x 18106338 x 3220138512 x 263222147/1112 x 364431209/1516 x 3664463012/2116 x 4898724714/25

Encoding

The data represented in the symbol is can be compressed using one or several of the following algorithms:

  • ASCII: it is used to encode data that mainly contains ascii characters (0-127). It encodes one alphanumeric or two numeric characters per byte.
  • C40: it is used to encode data that mainly contains numeric and upper case characters. C40 encodes three alphanumeric data characters into two bytes.
  • TEXT: it is used to encode data that mainly contains numeric and lowercase characters. TEXT encodes three alphanumeric data characters into two bytes.
  • BASE256: it is used to encode 8 bit values.

All encoding system can be used to encode any data, but for example, encoding binary data with C40 generates much more overhead (longer symbol) than with BASE256.

Control characters

RDataMatrix uses the character ~ to recognize some special characters in the input data. The following possibilities are available:

  • ~X is used to represent character values from 0 to 26. Replace the X like in the following example ~@ = means character ascii 0, ~A= means character 1, ~B=means character 2, ~C=means character 3 ...
  • ~1: represents the character FNC1. When FNC1 appears in the first position (or in the fifth position of the first symbol of a Structured Append), it will indicate that the data conforms to the UCC/EAN Application Identifier standard format.
  • ~2: It is used to represent Structured Append. Structured Append is used to link information from several symbols in a secuence. The ~2 must be followed by 3 additional bytes. The first 4 bits of thie first byte identify the position of the particular symbol in the secuence . The last 4 bits identify the total number of symbols in the secuence. The second and third byte are used as a file identifier are can have a value between 1 and 254 (up to 254*254=64516 identifiers). See Data Matrix Specification for more information about this (ISO 16022).
  • ~3: This character are only allowed in the first position of the symbol. It indicates that the data contains commands for the barcode reader.
  • ~4: not allowed.
  • ~5 and ~6: These characters are only allowed in the first position of the symbol. If ~5 is used the header [)> ascii30 ascii05 ascii29 will be transmitted by the barcode reader before the data in the symbol and the trailer ascii30 ascii04 will be transmitted after the data. If a ~6 is used , the header [)> ascii30 ascii05 ascii29 will be transmittedby the reader before the data and the trailer ascii30 ascii04 will be transmitted afterwards.
  • ~7NNNNNN specifies the Extended Channel to be used, where NNNNNN is a value between and 000000 - 999999. For example: ~7000010 means Extended Channel 10 . Extended channel is used for using other character sets other than ascii. See Data Matrix Specification for more information about this (ISO 16022).
  • ~dNNN represents the ascii character encoded by the 3 digits NNN. For exmaple, ~d065 represents the character 'A'.

Parameters and properties of the Java Class

RDataMatrix is an extension of RBarcode, therefore the some parameters are inherited from the BarCode class:

  • BARCODE: text to encode.
  • BACK_COLOR.
  • BAR_COLOR
  • ROTATE
  • CODE_TYPE: must have the value DATAMATRIX.

The specific parameters for this type of symbology are:

  • DM_DOT_PIXELS: size of the square modules in pixels (the default is 8 pixels)
  • DM_TILDE: if true ("Y") the tilde (~) will be processed as already explained. If not it will be treated as a normal character.
  • DM_MARGIN_PIXELS: quite zone around the symbol (the default is 30 pixels).
  • DM_ENCODING: the encoding to be used. The default is ASCII. Posible values are ASCII, C40, TEXT, BASE 256 and AUTO
  • DM_FORMAT: If empyte the format will be selected automatically, if not you can specify the format (e.g. C24X24).

 

QRCode, RSS, Aztec Code and Maxicode

The evaluation version and the documentation of these symbologies are available as a separate download from RBarcode download page.

Jasper Report and iReport Integration

You can use our barcode component in Jasper Reports in a very easy way.

If you are using Jasper Report without iReport

  1. Use the <image> tag to add an image to your report
  2. In the imageExpression part you enter the class net.sf.jasperreports.engine.JRRenderable.
  3. In the content of the expression you enter a reference to our components.

This is a very simple report which includes a barcode:

<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="Simple_Report">
<detail>
<band height="500">
<staticText>
<reportElement x="20" y="0" width="200" height="20"/>
<text><![CDATA[This is my first Barcode:]]></text>
</staticText>

<image hyperlinkType="None">
<reportElement x="20" y="20" width="100" height="50"/>
<imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[new com.java4less.rbarcode.jr.J4LBarcodeRenderer( (newcom.java4less.rbarcode.BarCodeFacade()).createBarcodeImage("CODE128","1234567890","A","false","1234567890",0,20,1,2,null,null,null,null,30,30,null))]]>
</imageExpression>
</image>

</band>
</detail>
</jasperReport>

the Java code to run this report would be (we assume the previous report has been copied to the file Report.jrxml):

import java.util.HashMap;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class MyReport {

public static void main(String[] args)
{
JasperReport jasperReport;
JasperPrint jasperPrint;
try
{

jasperReport = JasperCompileManager.compileReport("Report.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, "report.pdf");


}
catch (JRException e)
{
e.printStackTrace();
}
}
}

 

You will find some examples in the jasperreports subdirectory of the delivery.

The expression used for the other barcode types are:

  • PDF417

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer((new com.java4less.rbarcode.BarCode2DFacade()).createBarcodeImage("This is a PDF417",null,0,0,3,1,"TEXT",1,4,20,null) )

  • Datamatrix

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer((new com.java4less.rdatamatrix.RDataMatrixFacade()).createBarcodeImage("This is a Datamatrix",null,false,3,30,"AUTO",null,null) )

  • QRCode

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer((new com.java4less.qrcode.QRCodeFacade()).createBarcodeImage("This is a QRCode",null,3,false,20,"H","AUTO",1,null) )
  • AztecCode (contact us if you need the evaluation version)

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer((new com.java4less.raztec.AztecCodeFacade()).createBarcodeImage("data",null,3,false,20,23,"BINARY",2,1,null) )
  • Maxicode (contact us if you need the evaluation version)

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer((new com.java4less.rmaxicode.RMaxiCodeFacade()).createBarcodeImage("AAA",2,200,false,"056","B1050","999",25.5,null) )

Please check the JavaDoc subdirectory in the evaluation version. You will find there the documentation of the *Facade classes and the description of the paramters.

 

If you are using iReport

In this case you have to:

  1. Add rbarcode.jar and/or qrcode.jar to the reports classpath by selection main menu, options , classpath



  2. Add an image to your report
  3. In the image properties select Image Expression Class= net.sf.jasperreports.engine.JRRenderable
  4. In the Image expression field enter one of the expression as explained in the previous section, for example:

    new com.java4less.rbarcode.jr.J4LBarcodeRenderer( (newcom.java4less.rbarcode.BarCodeFacade()).createBarcodeImage("CODE128","1234567890","A","false","1234567890",0,20,1,2,null,null,null,null,30,30,null))



 

 

Barcoding Web Services

You can also use our barcode components as a web service. Follow this link to go to the web services page.

FOP plugin (PDF generation)

You can also include barcodes in your PDF files. Follow this link to go to the FOP plugin page.

Questions?

Contact us at java4less@confluencia.net if you have any questions.

 

原创粉丝点击