Using a Quick Response code to link to content
A Quick Response (QR) code is a type of two-dimensional bar code that contains encoded information. Figure 8‑14 shows an example of a QR code.
Figure 8‑14 A QR code
QR codes are used by a wide range of applications targeted to document management and mobile phone users. QR codes can store URLs, business card information, contact details, meeting schedules or any kind of text. Use a QR code in a report to provide contact information or links to other reports. Mobile phone users who have a QR code reader on their phone can scan the image of a QR code to display the contact information or open a report.
BIRT Designer Professional includes a QR code generator, for generating QR codes. To insert a QR code in a report, insert an image element to display the QR code. In the image’s onCreate or onRender event, write code to dynamically create the QR code.
To test QR code generation in BIRT Designer Professional, add core.jar or the most recent version of it to your Resources folder. This JAR file is available from the ZXing library at following URL:
http://code.google.com/p/zxing/
The code example in Listing 8‑3 creates a QR code that, when scanned, opens a report, qrreport.rptdesign, on a BIRT iHub.
Listing 8‑3 Code to create a QR code that opens a report
var size = 350; // image width and height in pixels
var bgnd = new Packages.java.awt.Color(1.0, 1.0, 1.0); // white background
var fgnd = new Packages.java.awt.Color(0, 0, 0); // black foreground
 
// Report URL to encode.
var message = "http://athena:8700/iportal/executereport.do?__executablename=/qrreport.rptdesign&invokeSubmit=true;"
 
var writer = new Packages.com.google.zxing.qrcode.QRCodeWriter();
var matrix = writer.encode(message, Packages.com.google.zxing.BarcodeFormat.QR_CODE, size, size);
 
var bi = new Packages.java.awt.image.BufferedImage(size, size, Packages.java.awt.image.BufferedImage.TYPE_INT_RGB);
var g = bi.getGraphics();
g.setColor(bgnd);
g.fillRect(0,0,size,size);
g.setColor(fgnd);
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if (matrix.get(x, y)) {
g.fillRect(x, y, 1, 1);
}
}
}
 
baos = new Packages.java.io.ByteArrayOutputStream();
Packages.javax.imageio.ImageIO.write(bi, "png", baos);
this.data = baos.toByteArray();
QR codes support up to 4,296 characters. The higher the number of characters, the higher the resolution of the QR code. Note, however, that low‑resolution mobile phone cameras might have difficulty reading high‑resolution codes.