How do I create barcode image without containing text at bottom using barbecue library

2k views Asked by At

I want to generate a barcode.png file but the file generated contains the Barcode number also and I don't want that, I only want image without Text.

How to do that? Below is my code:-

Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));`
2

There are 2 answers

0
Sunny On

The text will not generate in case you pass the null parameter to setFont function of Barcode class. Your code looks like as below

    Barcode barcode3;
    barcode3 = BarcodeFactory.createCode128("CODE128x1");
    barcode3.setFont(null);
    barcode3.setResolution(300);
    BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));
1
Johan On

only adding this to your code :

barcode3.setDrawingText(false);

the method above will remove text from the barcode. full code

Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setDrawingText(false);
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));