Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 149  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. google.zxing barcode generator in iReport
  2. package com.jaspersoft.alliances.mdahlman;
  3. import com.google.zxing.BarcodeFormat;
  4. import com.google.zxing.WriterException;
  5. import com.google.zxing.common.BitMatrix;
  6. import com.google.zxing.qrcode.QRCodeWriter;
  7. import com.google.zxing.client.j2se.MatrixToImageWriter;
  8. import net.sf.jasperreports.engine.JRDefaultScriptlet;
  9. import net.sf.jasperreports.engine.JRScriptletException;
  10.  
  11. public class QRCodeScriptlet extends JRDefaultScriptlet {
  12.     public void afterDetailEval() throws JRScriptletException {
  13.         QRCodeWriter writer = new QRCodeWriter();
  14.         BitMatrix matrix = null;
  15.         try {
  16.             matrix = writer.encode(getFieldValue("barcode_text").toString(), BarcodeFormat.QR_CODE, 256, 256);
  17.             this.setVariableValue("BarCodeImage", MatrixToImageWriter.toBufferedImage(matrix) );
  18.         } catch (WriterException e) {
  19.             e.printStackTrace();
  20.         }
  21.     }
  22. }
  23.        
  24. net.sourceforge.barbecue.BarcodeImageHandler.getImage(
  25. MyBarcodeGenerator.getFromString($F{field})
  26.        
  27. MatrixToImageWriter.toBufferedImage(new QRCodeWriter().encode("BARCODE CONTENT", BarcodeFormat.QR_CODE,     400 /*Width*/, 400/*Height*/));