Java Barcode Generator, .NET Barcode Generator for C#, ASP.NET, VB.NET
HOME PURCHASE SITEMAP COMPANY
Home > Products > Java Barcode > Java QR-Code


Java QR-Code Generator, Generating Barcode QRCode in Java, Jasper, BIRT projects

QR-Code is also known as Denso Barcode, QRCode, Quick Response Code, JIS X 0510, ISO/IEC18004

Quick Navigate
QR Code is a kind of 2-D (two-dimensional) symbology developed by Denso Wave (a division of Denso Corporation at the time) and released in 1994 with the primary aim of being a symbol that is easily interpreted by scanner equipment.

QR Code is capable of handling all types of data, such as numeric and alphabetic characters, Kanji, Kana, Hiragana, symbols, binary, and control codes.

The symbol versions of QR Code range from Version 1 to Version 40. Each version has a different module configuration or number of modules (the module refers to the black and white dots that make up QR Code). "Module configuration" refers to the number of modules contained in a symbol, commencing with Version 1 (21 x 21 modules) up to Version 40 (177 x 177 modules). Each higher version number comprises 4 additional modules per side. Each QR Code symbol version has the maximum data capacity according to the amount of data, character type and error correction level. In other words, as the amount of data increases, more modules are required to comprise QR Code, resulting in larger QR Code symbols.

QR Code has error correction capability to restore data if the code is dirty or damaged. Four error correction levels are available for users to choose according to the operating environment. Raising this level improves error correction capability but also increases the amount of data QR Code size. To select error correction level, various factors such as the operating environment and QR Code size need to be considered. Level Q or H may be selected for factory environment where QR Code gets dirty, whereas Level L may be selected for clean environment with the large amount of data. Typically, Level M (15%) is most frequently selected. The QR Code error correction feature is implemented by adding a Reed-Solomon Code to the original data.
QR Code is a matrix symbology with the following characteristics:
  1. Formats: QR Code, with full range of capabilities and maximum data capacity;
  2. Encodable character set:
    • numeric data (digits 0 - 9);
    • alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : );
    • byte data (default: ISO/IEC 8859-1);
    • Kanji characters.
  3. Version (Symbol size) (not including quiet zone): 21 x 21 modules to 177 x 177 modules (Versions 1 to 40, increasing in steps of four modules per side).
  4. Maximum QR Code symbol size, Version 40-L:
    • numeric data: 7089 characters
    • alphanumeric data: 4296 characters
    • Byte data: 2953 characters
    • Kanji data: 1817 characters
  5. Selectable error correction level:
    Four levels of Reed-Solomon error correction (referred to as L, M, Q and H in increasing order of capacity) allowing recovery of:
    • L 7%
    • M 15%
    • Q 25%
    • H 30%
    of the symbol codewords.
  6. Structured Append: This allows files of data to be represented logically and continuously in up to 16 QR Code symbols. These may be scanned in any sequence to enable the original data to be correctly reconstructed.
  7. Extended Channel Interpretations: This mechanism enables data using character sets other than the default encodable set (e.g. Arabic, Cyrillic, Greek) and other data interpretations (e.g. compacted data using defined compression schemes) or other industry-specific requirements to be encoded.
  8. FNC1 Mode: FNC1 mode is used for messages containing specific data formats. In the "1st position" it designates data formatted in accordance with the GS1 General Specifications. In the "2nd position" it designates data formatted in accordance with a specific industry application previously agreed with AIM Inc. FNC1 mode applies to the entire symbol and is not affected by subsequent mode indicators.
Java QR-Code Generator supports:
  • numeric data (digits 0 - 9);
  • alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : );
  • byte data (default: ISO/IEC 8859-1);
  • Kanji characters.

The following code illustrates how to create a barcode in a Java class

1            QRCode barcode = new QRCode(); 
2            barcode.setData("123456789"); 
4            barcode.renderBarcode("c:/qrcode.gif"); 


  • Create a QRCode object (line 1)
  • set QRCode object properties (line 2)
  • save into gif file (line 4)

There are two ways to create barcode images in your Java web applications.

  1. This is the simplest way to stream barcode image using our provided barcode servlet classes.

    And it will not save barcode images in your server side.

    • Under demo package, copy barcode folder to your java servlet container like tomcat.

    • To test your installation, goto http://YourDomain:Port/barcode/qrcode?Data=123456789

    • To create barcode image in your JSP or html page, you can pass the url to IMG tag src value. For example, <img src="http://YourDomain:Port/barcode/qrcode?Data=123456789" />

  2. The second method is similar with the way to generate barcode in Java applications.

    • Create a barcode image in server side

      1            QRCode barcode = new QRCode(); 
      2            barcode.setData("123456789"); 
      4            barcode.renderBarcode("C:/Tools/Tomcat 5.5/webapps/YourWebApp/bimages/qrcode.gif"); 
      
      
      

    • In your JSP page, you can using IMG tag to display generated image, like <img src="http://YourDomain:Port/YourWebApp/bimages/qrcode.gif" />

The following jasper xml content illustrates how to insert a barcode into JasperReports

<import value="com.barcodelib.barcode.BarcodeJasperFactory"/> 

Import class BarcodeJasperFactory to report.

<image scaleImage="Clip" hAlign="Center"> 
    <reportElement x="50" y="110" width="515" height="120"/> 
    <graphicElement/> 
    <imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[new com.barcodelib.barcode.BarcodeJasperRenderer(BarcodeJasperFactory.createQRCode("123456789", 0, 1))]]></imageExpression> </image>

Please go to class BarcodeJasperFactory in Java doc for all methods to create barcode.

Developers can also extend or modify BarcodeJasperFactory class to meet their own requirements. Complete BarcodeJasperFactory.java Source Code

Our Java barcode library supports generating barcode image in Eclipse BIRT framework.

Click here to view the details.

Just call QRCode object method renderBarcode, e.g. barcode.renderBarcode("c:/qrcode.gif");
  • Set the data property with the value to encode. Type is String.
    Servlet Parameter: "Data".
  • Set the dataMode property. Default is QRCode.MODE_AUTO.
    • QRCode.MODE_AUTO: It allows encoding all 256 possible 8-bit byte values. This includes all ASCII characters value from 0 to 127 inclusive and provides for international character set support
    • QRCode.MODE_ALPHANUMERIC: It allows encoding alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : ).
    • QRCode.MODE_BYTE: It allows encoding byte data (default: ISO/IEC 8859-1).
    • QRCode.MODE_NUMERIC: It allows encoding numeric data (digits 0 - 9).
    • QRCode.MODE_KANJI: It allows encoding Kanji characters.

    Servlet Parameter: "DataMode".
  • Set the version property. Default is 1. Valid values are from 1 to 40. About Version and Symbology Size
    Servlet Parameter: "Version".
  • Set the ecl property. QRCode Error Correction Level. Default is QRCode.ECL_L (0). About Error Correction Level
    • QRCode.ECL_L (0)
    • QRCode.ECL_M (1)
    • QRCode.ECL_Q (2)
    • QRCode.ECL_H (3)

    Servlet Parameter: "ECL".
  • QR Code can be divided into multiple data areas. Conversely, information stored in multiple QR Code symbols can be reconstructed as single data symbols. One data symbol can be divided into up to 16 symbols.
    • Set isStructuredAppend property to true, then Structured Append is enabled. About Structure Append
      Servlet Parameter: "IsStructuredAppend".
    • Set symbolCount property to the number of total symbols which make the sequence.
      Servlet Parameter: "SymbolCount".
    • Set symbolIndex property to the position of current symbol in the secuence (Start with 0).
      Servlet Parameter: "SymbolIndex".
  • Set the FNC1Mode property. About FNC1 Mode
    • QRCode.FNC1_NONE (0)
    • QRCode.FNC1_1ST_POS (1)
    • QRCode.FNC1_2ND_POS (2)

    Servlet Parameter: "FNC1Mode".
  • Set the applicationIndicator property. Please set this property, if property FNC1Mode value is QRCode.FNC1_2ND_POS (2).
    Servlet Parameter: "ApplicationIndicator".
  • Set the ECI property. The type is int. Valid values are from 000000 to 999999. About Extended Channel Interpretations
    Servlet Parameter: "ECI".
  • Setting up barcode image size and style:
    • Set property uom (Unit of Measure) for properties moduleSize, leftMargin, rightMargin, topMargin and bottomMargin.
      Default is QRCode.UOM_PIXEL (0). Valid values are QRCode.UOM_PIXEL (0), QRCode.UOM_CM (1), QRCode.UOM_Inch (2).
      Servlet Parameter: "UOM".
    • Set the moduleSize (for bar cell width and height). Type is float, and default is 1.
      Servlet Parameter: "ModuleSize".
    • Set the leftMargin, rightMargin, topMargin and bottomMargin properties.
      Types are all float. Default are 4 * moduleSize.
      Servlet Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin".
    • Set the barcodeWidth (barcode image width) and barcodeHeight (barcode image height) properties. Both types are float.
      Servlet Parameter: "BarcodeWidth", "BarcodeHeight".
    • Set the resolution property (Value is expressed in DPI - Dots per inch).
      Servlet Parameter: "Resolution".
  • Set rotate property, if you want to rotate barcode image.
    Value can be
    0 (QRCode.ANGLE_0),
    1 (QRCode.ANGLE_90),
    2 (QRCode.ANGLE_180),
    3 (QRCode.ANGLE_270)
    Servlet Parameter: "Rotate".
  • Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is false.
    ~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
    Servlet Parameter: "ProcessTilde".

To set barcode image width and height, there are two ways to do it.

1) You can set barcode image width and height through properties barcodeWidth and barcodeHeight values, barcode library will render the barcode image for you.

or

2) You can set moduleSize value (barcode module width and height value), barcode library will calculate the barcodeWidth and barcodeHeight values for you, and render the barcode image.

1) set dataMode value to QRCode.MODE_AUTO or QRCode.MODE_KANJI.

2) set processTilde value to true.

3) set Kanji value. there are two ways to set kanji data value. According to QRCode specification, library is using Shift JIS encoding system.

      a) call method setKanjiData(int[] binaryData). Each int value represent one kanji character in Shift JIS encoding. Valid kanji values in Shift JIS encoding are from 0x8140 to 0x9FFC, and from 0xE040 to 0xEBBF.
            Please do not set data value here.

      b) set property data. Use "~9NNNNN" to represent each Kanji character in Shift JIS encoding.

For example, input character . Shift JIS Value is 0x935F, and int value is 37727.
in method a, you call setKanjiData({37727}).
in method b, you set data = "~937727".

All Java Barcode Types/Symbologies


 







   Copyright 2009 BarcodeLib.com. Provides High Quality Java Barcode, Barcode Java, Java Barcode Generator. All rights reserved.