Java QR Code Generator Introduction
Java Barcode is a Java barcode generator which generates high quality 1D (linear) and 2D (matrix) barcodes in Java, Jasper Reports, iReport, and Eclipse BIRT projects.
You can download the Java Barcode creator library SDK trial package to create QR Code barcodes in your Java projects. The download the package includes compiled Java barcode generation SDK (a single Jar file), detailed tutorial for creating barcodes in Java, and complete sample Java source code to generate QR Code in Java class. Using downloaded Java barcode generation SDK, you can also easily create and print
Data Matrix, PDF417, Code 39, Code 128, EAN, UPC, and other linear and 2d barcodes.
You can download the Java Barcode creator library SDK trial package to create QR Code barcodes in your Java projects. The download the package includes compiled Java barcode generation SDK (a single Jar file), detailed tutorial for creating barcodes in Java, and complete sample Java source code to generate QR Code in Java class. Using downloaded Java barcode generation SDK, you can also easily create and print
Data Matrix, PDF417, Code 39, Code 128, EAN, UPC, and other linear and 2d barcodes.
QR Code Introduction
QR Code is a matrix code (or two-dimensional bar code) created by Japanese corporation Denso-Wave in 1994. The "QR" is derived from "Quick Response", as the creator intended the code to allow its contents to be decoded at high speed.
Java QR-Code Generator - Valid Data Scope
Java QR Code Generator encodes:
In this page, you will learn how to create, customize, print QR Code images in Java class, Java web application.
- 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.
In this page, you will learn how to create, customize, print QR Code images in Java class, Java web application.
| QR Code with URL encoded | QR Code with logo image printed |
|
|
How to Generate QR Code in Java Class?
Using Java Barcode Generator library API, you can quickly create and print QR Code images in Java application.
- Create a
com.onbarcode.barcode.QRCodeobject - Set the QR Code encoding text using method
setData() - Call method
drawBarcode()to draw QR Code to a png image file
QRCode barcode = new QRCode(); barcode.setData("https://www.onbarcode.com"); try { barcode.drawBarcode("c://Output//OnBarcode.com//java-qrcode-demo.png"); } catch (Exception e) { e.printStackTrace(); }
Print QR Code in memory
You can also print QR Code in memory object in Java application, and apply further processing on the generated QR Code object in Java codes.
drawBarcode(), returnjava.awt.image.BufferedImageobject containing QR Code image datadrawBarcode(java.awt.Graphics2D g, java.awt.geom.Rectangle2D rectangle)allows you to encode draw QR Code on a JavaGraphics2Dobject inside a rectangledrawBarcode(java.io.OutputStream outputStream)print QR Code on a JavaStreamobjectdrawBarcodeToBytes()create and draw QR Code image to an byte array object
QR Code Data Encoding using Java Barcode library
QR Code is one of the 2D barcode, which supports various text formats encoding. Using Java Barcode library, you can easily convert the following text or data formats to QR Code images in Java projects.
- Plain English text using 128 Full ASCII characters
- Unicode text
- Binary data
- GS1 business data message
Convert ASCII chars to QR Code
It is an easy job to encode and convert plain English text (ASCII characters) to QR Code using Java.
- Set the QR Code encoding ASCII chars using
setData()method, such asbarcode.setData("your text here") - Call method
drawBarcode()to print QR Code to an image file or object in Java memory
Encode ASCII non-printing chars
ASCII character table includes 33 non-printing chars (control characters), you cannot directly key-in these characters from your keyboard. To encode ASCII non-printing chars in QR Code,
Java Barcode library provides method to support it.
- Enable property
ProcessTildeby callingsetProcessTilde(true) - Set QR Code data mode as
Autoin methodsetDataMode(QRCode.M_AUTO) - In QR Code encoding data property, you need convert each the non-printing character to ASCII value in 3-digit format with '~' in the beginning.
For example, char "carriage return" or '[CR]' ASCII value is 13. You need use the string text "~013" to encode char
[CR]in QR Code.
QRCode barcode = new QRCode(); barcode.setProcessTilde(true); barcode.setDataMode(QRCode.M_AUTO); barcode.setData("~013"); barcode.drawBarcode("c://Output//OnBarcode.com//java-qrcode-ascii-non-printing-chars.png");
Convert Unicode text to QR Code
Here are the sample Java source code to generate QR Code with Unicode text encoded.
- Create a new
QRCodeobject in Java program - Enable property
EncodeUnicodeTextby calling methodsetEncodeUnicodeText(true) - Input the Unicode text in property
Data. Here we have provided a simple Chinese text, meaning hello in Chinese. - Call method
drawBarcodeto print the QR Code to a PNG image file
QRCode barcode = new QRCode(); barcode.setEncodeUnicodeText(true); barcode.setData("你好"); barcode.drawBarcode("c://Output//OnBarcode.com//java-qrcode-unicode-text.png");
UTF8 & UTF16 encoding
In the above Java sample code, the barcode library will generate QR Code using
UTF8 encoding. You can select other text encoding format by calling
method setUnicodeEncoding()
// Set unicode encoding mode that is used for the input message in Encode Unicode Text mode. // Ignore this property if property EncodeUnicodeText is false. // value (int): Unicode Encoding ID // Valid Mode ID // IBarcode.TEXT_ENCODING_UTF8: for UTF-8 (Default) // IBarcode.TEXT_ENCODING_UTF16: for UTF-16 // IBarcode.TEXT_ENCODING_UTF16BE: for UTF-16 big endian // IBarcode.TEXT_ENCODING_UTF16LE: for UTF-16 little endian public void setUnicodeEncoding(int value)
How to Resize Generated Barcode QR-Code Image Width and Height?
- You can set barcode image width and height through properties barcodeWidth and barcodeHeight values.
- Or you can set X (bar module width) and Y (bar module height) values
How to create styled QR Code with logo image using Java?
Now QR Codes connect the physical and digital worlds. A standard and ISO compatible QR Code cannot meet business and marketing requirements.
We need more extra requirements for QR Code, including displaying logos, styled colors.
Here we will demonstrate how to create and print a styled QR Code with logo image in Java class.
Here is a QR Code with logo image printed in the web page in the Java web application.
Here we will demonstrate how to create and print a styled QR Code with logo image in Java class.
- Create a
QRCodeobject - Set the QR Code encoding data using method
setData - Select the logo image using method
setLogo - Set logo image width and height using method
setLogoActualWidthandsetLogoActualHeight - Set QR Code error correction level through method
setEcl - Create and print QR Code with logo image embeded
QRCode barcode = new QRCode(); barcode.setData("https://www.facebook.com"); barcode.setLogo(ImageIO.read(new File("C://Input//facebook.png"))); barcode.setLogoActualWidth(60); barcode.setLogoActualHeight(60); barcode.setEcl(QRCode.ECL_M); barcode.drawBarcode("C://demo//qrcode-styled-logo.png");
Here is a QR Code with logo image printed in the web page in the Java web application.
How to create, customize QR Code options in Java application?
QR Code error correction mode
Four levels of Reed-Solomon error correction (referred to as L, M, Q and H in increasing order of
capacity) allowing recovery of the QR Code barcode data.
- L: 7% (default)
- M: 15%
- Q: 25%
- H: 30%
Using Java QR Code Generation library, you shall set QR Code error correction mode through property
Top
Top
Top
Top
What does QR stand for in code?
What is the smallest size a QR Code can be printed?
How to create a QR Code for a picture?
Does the color of a QR Code matter?
How much data can be stored in a QR code?
What is the difference between a barcode and a QR Code?
ECL.
The default "ECL" value is QRCodeECL.L. You can view the QR Code error correction level Java demo code below.
QRCode barcode = new QRCode(); barcode.setData("QR Code"); barcode.setDataMode(QRCode.M_AUTO); /* QRCode Error Correction Level. Default is QRCode.ECL_L (0). QRCode.ECL_L (0) QRCode.ECL_M (1) QRCode.ECL_Q (2) QRCode.ECL_H (3) */ barcode.setEcl(QRCode.ECL_M);
QR Code Version
In QR Code ISO standard, it defines forty sizes of QR Code barcode referred to as Version 1, Version 2 ... Version 40.
View details at How to set QR Code Versions
Using Java QR Code generator api, you shall set property
View details at How to set QR Code Versions
Using Java QR Code generator api, you shall set property
Version with an interger value, from 1 to 40.
barcode.setVersion(3);
QR Code Structured Append mode
A large data message can be divided and stored in up to 16 QR Code barcodes using QR Code structured Append mode.
In Java QR Code generator sdk library, to implement Structured Append mode, you should apply the following property options :
- StructuredAppend: Set value to true, to enable Structured Append mode in QR Code
- SymbolCount: Total number of symbols for one QR Code data message
- SymbolIndex: The position of current symbol in the sequence (The first symbol index is 0)
- Parity: All QR Codes to store the same text message should have the same
Parityvalue.
barcode.setStructuredAppend(true); barcode.setSymbolCount(3); barcode.setSymbolIndex(0); barcode.setParity(999);
QR Code GS1 Text and FNC1 in first position
This QR Code FNC1 mode indicator identifies the current QR Code encoding data formatted according to the GS1 Application Identifiers standard.
To enable this mode using Java QR Code generator library, you need apply the following property in the Java source code below.
To enable this mode using Java QR Code generator library, you need apply the following property in the Java source code below.
- Set property
FNC1with valueFNC1.FNC1_1ST_POS
QRCode barcode = new QRCode(); barcode.setFnc1Mode(IBarcode.FNC1_ENABLE); barcode.setData("(17)050101(10)ABC123"); barcode.drawBarcode("C://Output//java-qrcode-mode-gs1.png");
How to Create QR Code Image in Html or JSP Pages?
- Under demo package, copy barcode folder and its contents to your tomcat.
- Start tomcat, navigate to http://YourDomain:Port/barcode/barcode?DATA=QRCodeEncodingData&TYPE=qrcode
- To create bar code images in html or jsp pages, you can insert a image tag (img) into your page.
- For example, <img src="http://YourDomain:Port/barcode/barcode?DATA=QRCodeEncodingData&TYPE=qrcode" />
How to Generate QR Code Image in Java Servlet Class?
import com.onbarcode.barcode.AbstractBarcode;
import com.onbarcode.barcode.QRCode;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
public class BarcodeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try {
QRCode barcode = new QRCode();
barcode.setData("QRCode");
ServletOutputStream servletoutputstream = response.getOutputStream();
response.setContentType("image/jpeg");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// Generate QRCode barcode & output to ServletOutputStream
barcode.drawBarcode(servletoutputstream);
} catch (Exception e) {
throw new ServletException(e);
}
}
}
How to Generate & Print QR Code in Java Reports (Jasper, iReport, BIRT reports)?
Using OnBarcode Java Barcode Generator library API, you can generate and print QR Codes in Java reporting applications. The barcode library supports QR Codes generation
in iReport, Jasper Reports, Eclipse BIRT reports Java projects. View detailed developer guide below:
Java QR Code Generator - Barcode Property Settings
Java QR Code Generator in Java Class: com.onbarcode.barcode.QRCode
View the details here: complete QR Code property settings in Java class
View the details here: complete QR Code property settings in Java class
Common Asked Questions
What does QR stand for in code?
QR stands for "quick response", and QR Code is a 2-dimensional matrix barcode on steroids. The QR code stores data information both horizontally and vertically.
OnBarcode Java Barcode Generator library supports QR Code generation in Java class, Jasper Reports, iReport in Java projects.
What is the smallest size a QR Code can be printed?
If your QR Code will be scanned by QR Code scanner devices, the minimum size for a QR Code is 1 x 1 cm. However if the QR Code will be scanned by smartphones (iOS or Android),
most the barcode scanner app requires that the minimum size for a QR Code is 2 x 2 cm.
Using Java QR Code Generator library, you can create and customize the printed QR Code dimension size through methods
Using Java QR Code Generator library, you can create and customize the printed QR Code dimension size through methods
QRCode.setBarcodeWidth() in class com.onbarcode.barcode.QRCode
How to create a QR Code for a picture?
To create a QR code from a photo or an image in Java project
- Convert the photo image raw data into byte array
- Create a
QR Codeobject - Set the QR Code data mode in method
setDataMode()withQRCode.M_BYTEas parameter - Set
setProcessTilde()with valuetrue - Set QR Code encoding data through method
setData() - Print and output QR Code to an image file
Does the color of a QR Code matter?
Choose whatever colors you want but always make sure the back and fore colors have strong contrast.
We suggest at least 70% darker to ensure reliable scanning, and always scan and verify your QR code to make sure it works using the colors you've chosen.
In Java class, you can create and initiate a
In Java class, you can create and initiate a
QRCode object to generate QR Code barcode images,
and customize the QR Code bar color through method setForeColor(),
and the QR Code background color through method setBackColor(), in Java class QRCode
How much data can be stored in a QR code?
A standard QR Code can store up to three kilobytes (KB) of data. A QR Code symbol with version 40-L can hold the following data information:
- numeric data: 7,089 characters
- alphanumeric data: 4,296 characters
- byte data: 2,953 characters
- Kanji data: 1,817 characters
QRCode object to generate QR Code barcode images,
and set the encode the data through method setData().
What is the difference between a barcode and a QR Code?
Barcode is usually known as 1d or linear barcode symbology, which can store limited number of characters.
QR Code or Quick Response code, is a type of two-dimensional code that can hold more than 4,200 alphanumeric characters.
Using OnBarcode Java Barcode Generator library, you can create QR Code (standard, GS1, Micro, Macro versions) and other 20+ 2d, 1d barcodes such as Code 128, Data Matrix, EAN/UPC barcodes in Java class, JSP, Servlet, iReport, JasperReports, BIRT reports applications.
Using OnBarcode Java Barcode Generator library, you can create QR Code (standard, GS1, Micro, Macro versions) and other 20+ 2d, 1d barcodes such as Code 128, Data Matrix, EAN/UPC barcodes in Java class, JSP, Servlet, iReport, JasperReports, BIRT reports applications.
