Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable text below barcode image in Code39Bean

Tags:

java

This code creates BarCode Image along with Text below image . I need to remove the text from image . Code39Bean does not have any property to disable this .

public static ByteArrayOutputStream generateBarcodeImg(String inputId)
            throws Exception {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        Code39Bean bean = new Code39Bean();
        final int dpi = 150;

        /**
         * Configure the bar-code generator and makes the narrow bar width
         * exactly one pixel.
         */
        bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi));
        bean.setWideFactor(3);
        bean.doQuietZone(false);

        try {

            /** Set up the canvas provider for monochrome PNG output. */
            BitmapCanvasProvider canvas = new BitmapCanvasProvider(baos,
                    BarCodeConstant.CONTENT_TYPE, dpi,
                    BufferedImage.TYPE_BYTE_BINARY, false, 0);

            /** Generate the bar code. */
            bean.generateBarcode(canvas, inputId);

            /** Signal end of generation. */
            canvas.finish();
        } catch (IOException e) {
            logger.error(
                    "Exception occured in BarcodeGeneration: generateBarcodeImg "
                            + e.getLocalizedMessage(), e);
            throw new MobileResourceException(
                    "Exception occured in BarcodeGeneration: generateBarcodeImg",
                    null);
        }
        return baos;

    }
}
like image 293
user3571547 Avatar asked Jun 28 '26 19:06

user3571547


1 Answers

You can remove the text from Image through the "HumanReadablePlacement" property:

bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);

This will suppress the human readable text of the barcode to NONE.

like image 58
Semir_Ibrahim Avatar answered Jun 30 '26 08:06

Semir_Ibrahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!