Developer Guide >
QRCode Generation Guide
QR Code Barcode Sample Code & Barcode Property Settings
1. Generate QRCode in Java Class
The following Java code illustrates how to generate a QRCode barcode in a Java class
QRCode barcode = new QRCode();
barcode.setData("A");
barcode.setDataMode(QRCode.MODE_BYTE);
barcode.setVersion(10);
barcode.setEcl(QRCode.ECL_M);
barcode.setUOM(uom);
barcode.setModuleSize(moduleSize);
barcode.setLeftMargin(leftMargin);
barcode.setRightMargin(rightMargin);
barcode.setTopMargin(topMargin);
barcode.setBottomMargin(bottomMargin);
barcode.setResolution(resolution);
barcode.setRotate(rotate);
barcode.renderBarcode("C://qrcode.gif");
// generate barcode to BufferedImage object
BufferedImage bufferedImage = linear.renderBarcode();
// generate barcode to byte[] object
byte[] barcodeBytes = linear.renderBarcodeToBytes();
// render barcode on Graphics2D
Graphics2D g = ...
Rectangle2D rectangle = ...
linear.renderBarcode(g, rectangle);
// generate barcode and output to OutputStream object
OutputStream outputStream = ...
linear.renderBarcode(outputStream);
2. Java QR-Code Property Settings
-
Set the data property with the value to encode. Type is String.
Servlet URL Parameter: "Data".
-
Set the dataMode property. Default is QRCode.MODE_AUTO.
-
QRCode.MODE_AUTO (0 default): 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 (1): It allows encoding alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : ).
-
QRCode.MODE_BYTE (2): It allows encoding byte data (default: ISO/IEC 8859-1).
-
QRCode.MODE_NUMERIC (3): It allows encoding numeric data (digits 0 - 9).
-
QRCode.MODE_KANJI (4): It allows encoding Kanji characters.
Servlet URL Parameter: "DataMode". Sample: &DataMode=0
-
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the encoding data. Default is false.
Format of the tilde:
- ~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
- ~6NNNNN: is used to represent the Unicode. NNNNN is from 00000 - 65535.
-
~7NNNNNN: is used to specify the Extended Channel Interpretations and NNNNNN is a value between
000000 and 999999.
-
~9NNNNN: is used to represent the Shift JIS. It is for Shift JIS 0x8140 ~ 0x9FFC and 0xE040 ~ 0xEBBF.
Servlet URL Parameter: "ProcessTilde". Value: "t" (true), "f" (false). Sample: &ProcessTilde=t
-
Set the version property. Default is 1. Valid values are from 1 to 40. About Version and Symbology Size
Servlet URL Parameter: "Version". Sample: &Version=1
-
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 URL Parameter: "ECL". Sample: &ECL=0
-
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.
Servlet URL Parameter: "FNC1Mode". Sample: FNC1Mode=0
-
Barcode image size settings: How to control barcode size?
-
Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin.
Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2).
Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0
-
Set the moduleSize (for barcode module width & height) property.
Type is float. Default is 1.
Servlet URL Parameter: "ModuleSize". Sample: &ModuleSize=5
-
Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float.
Default values are 0 for all 4 margin settings.
Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0
-
Set the resolution property (Value is expressed in DPI - Dots per inch).
Default is 72 dpi.
Servlet URL Parameter: "Resolution". Sample: &Resolution=72
-
With rotate property, you can display barcode horizontally or vertically.
Value can be
- 0 (Linear.ANGLE_0),
- 1 (Linear.ANGLE_90),
- 2 (Linear.ANGLE_180),
- 3 (Linear.ANGLE_270)
Default value is 0.
Servlet URL Parameter: "Rotate". Sample: &Rotate=0
3. Encoding GS1 Compatible QR Code
- Set property fnc1Mode value to 1, which indicates that you are encoding GS1 compatible QR Code
- You can use (dddd) format to encode AI code "dddd".
For example, to encode AI code 21 with value d12345777,
and AI code 21 with value 12345678.
barcode.setData("AI(21)d12345777AI(21)12345678").
4. All Barcode Types
|