Using a Quick Response (QR) code to link to content
A QR code is a type of two-dimensional barcode that contains encoded information. Figure 14-7 shows an example of a QR code.
Figure 14-7  
QR codes are used by a wide range of applications targeted to mobile-phone users. QR codes can store URLs, business card information, 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.
Actuate BIRT Designer includes a QR code generator, ZXing, 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. Listing 14-1 shows a code example that creates a QR code that when scanned opens a report, qrreport.rptdesign, on an Actuate BIRT iServer.
Listing 14-1  
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:8910/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);
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 not be able to read high-resolution codes.

Additional Links:

Copyright Actuate Corporation 2012