Example usage for com.itextpdf.text.pdf Barcode39 createAwtImage

List of usage examples for com.itextpdf.text.pdf Barcode39 createAwtImage

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf Barcode39 createAwtImage.

Prototype

public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background) 

Source Link

Document

Creates a java.awt.Image.

Usage

From source file:com.betel.flowers.pdf.util.BarcodeGenerator.java

public static boolean createBarCode(String direccionXML, String direccionDestinoHtml) {
    Boolean exito = false;//from   ww  w .  j  a  va  2s  .  c  om
    try {
        String directorioDestino = direccionDestinoHtml;
        File archivo = new File(direccionXML);
        String claveAcceso = getClaveAcceso(archivo);
        StringBuilder sbca = new StringBuilder(claveAcceso);
        Barcode39 code39 = new Barcode39();
        code39.setCode(sbca.toString());
        code39.setX(0.75f);
        code39.setBarHeight(50f);
        java.awt.Image im = code39.createAwtImage(Color.WHITE, Color.BLACK);
        int w = im.getWidth(null);
        int h = im.getHeight(null);
        int type = BufferedImage.TYPE_INT_RGB; // other options
        BufferedImage dest = new BufferedImage(w, h, type);
        Graphics2D g2 = dest.createGraphics();
        g2.drawImage(im, 0, 0, null);
        g2.dispose();
        StringBuilder dirDestino = new StringBuilder(directorioDestino);
        dirDestino.append("/");
        dirDestino.append(claveAcceso);
        dirDestino.append(".gif");
        ImageIO.write(dest, "gif", new FileOutputStream(dirDestino.toString()));

    } catch (Exception ex) {
        System.out.println("no se pudo generar el codigo de barras " + ex.toString());
    }

    return exito;
}

From source file:com.divudi.bean.BarcodeController.java

public byte[] getBarcodeBytes(String code) {
    Barcode39 code39 = new Barcode39();
    code39.setCode(code);/*from   w w  w  .j av a  2  s.  c o m*/
    code39.setFont(null);
    code39.setExtended(true);
    Image image = null;
    try {
        image = Image.getInstance(code39.createAwtImage(Color.BLACK, Color.WHITE), null);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(BarcodeController.class.getName()).log(Level.SEVERE, null, ex);
    }
    return image.getRawData();
}