Exemplo n.º 1
0
  private static Image getBarcode(String value, AbstractBarcodeBean barcode) {

    barcode.setModuleWidth(1.0);
    barcode.setBarHeight(40.0);
    barcode.setFontSize(10.0);
    barcode.setQuietZone(10.0);
    barcode.doQuietZone(true);
    BarcodeDimension dim = barcode.calcDimensions(value);
    int width = (int) dim.getWidth(0) + 20;
    int height = (int) dim.getHeight(0);

    BufferedImage imgtext = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = imgtext.createGraphics();

    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, width, height);

    g2d.setColor(Color.BLACK);

    try {
      barcode.generateBarcode(new Java2DCanvasProvider(g2d, 0), value);
    } catch (IllegalArgumentException e) {
      g2d.drawRect(0, 0, width - 1, height - 1);
      g2d.drawString(value, 2, height - 3);
    }

    g2d.dispose();

    return imgtext;
  }
Exemplo n.º 2
0
 public static Image getBarcode128(String value) {
   AbstractBarcodeBean barcode = new Code128Bean();
   barcode.setMsgPosition(HumanReadablePlacement.HRP_NONE);
   return getBarcode(value, barcode);
 }
Exemplo n.º 3
0
 public static Image getBarcodeEAN13(String value) {
   AbstractBarcodeBean barcode = new EAN13Bean();
   barcode.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM);
   return getBarcode(value, barcode);
 }