Example usage for com.itextpdf.text.pdf BarcodeDatamatrix generate

List of usage examples for com.itextpdf.text.pdf BarcodeDatamatrix generate

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BarcodeDatamatrix generate.

Prototype

public int generate(String text) throws UnsupportedEncodingException 

Source Link

Document

Creates a barcode.

Usage

From source file:clienteditor.MakeBarcode.java

private static boolean make(BarcodeDatamatrix barcode, String code, String fileName) {
    try {//from  w ww.j  a  v  a2 s .co m
        barcode.generate(code);
        return writeToPngFile(barcode.createAwtImage(COLOR_FORE, COLOR_BACK), fileName);
    } catch (UnsupportedEncodingException e) {
        return false;
    }
}

From source file:ro.nextreports.engine.exporter.ResultExporter.java

License:Apache License

private void generateBarcodeImage(BarcodeBandElement bandElement) {
    if (bean.getConnection() == null) {
        return;//from w w  w .  j  av  a  2 s.  c  o m
    }
    int width = (bandElement.getWidth() == null) ? 1 : bandElement.getWidth();
    int height = (bandElement.getHeight() == null) ? 1 : bandElement.getHeight();
    String value = bandElement.getValue();
    if (bandElement.isColumn()) {
        try {
            value = String.valueOf(getResult().nextValue(value));
        } catch (QueryException e) {
            e.printStackTrace();
        }
    }
    Image image = null;
    if (BarcodeBandElement.isEANFamily(bandElement.getBarcodeType())) {
        BarcodeEAN codeEAN = new BarcodeEAN();
        codeEAN.setCodeType(bandElement.getBarcodeType());
        codeEAN.setCode(value);
        image = codeEAN.createAwtImage(Color.BLACK, Color.WHITE);
    } else {
        if (bandElement.getBarcodeType() == BarcodeBandElement.PDF417) {
            BarcodePDF417 barcode417 = new BarcodePDF417();
            barcode417.setText(value);
            image = barcode417.createAwtImage(Color.BLACK, Color.WHITE);
        } else if (bandElement.getBarcodeType() == BarcodeBandElement.DATAMATRIX) {
            BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
            try {
                datamatrix.generate(value);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            image = datamatrix.createAwtImage(Color.BLACK, Color.WHITE);
        } else if (bandElement.getBarcodeType() == BarcodeBandElement.QRCODE) {
            BarcodeQRCode qrcode = new BarcodeQRCode(value, width, height, null);
            image = qrcode.createAwtImage(Color.BLACK, Color.WHITE);
        } else {
            Barcode barcode = null;
            if (bandElement.getBarcodeType() == BarcodeBandElement.CODE128) {
                barcode = new Barcode128();
            } else if (bandElement.getBarcodeType() == BarcodeBandElement.CODE128_RAW) {
                barcode = new Barcode128();
                barcode.setCodeType(bandElement.getBarcodeType());
            } else if (bandElement.getBarcodeType() == BarcodeBandElement.INTER25) {
                barcode = new BarcodeInter25();
            } else if (bandElement.getBarcodeType() == BarcodeBandElement.CODE39) {
                barcode = new Barcode39();
            } else if (bandElement.getBarcodeType() == BarcodeBandElement.CODE39EXT) {
                barcode = new Barcode39();
                barcode.setStartStopText(false);
                barcode.setExtended(true);
            } else if (bandElement.getBarcodeType() == BarcodeBandElement.CODABAR) {
                barcode = new BarcodeCodabar();
            }
            barcode.setCode(value);
            image = barcode.createAwtImage(Color.BLACK, Color.WHITE);
        }
    }
    String imageName = saveBarcode(bandElement, toBufferedImage(image), "png");
    bandElement.setImage(imageName);
}