user2653936
user2653936

Reputation: 99

How to create barcode image with interleaved2of5 without displaying its text

I am using itext pdf jars to generate the barcode image using inter2of5.

How can I display barcode image only and not display the text (barcode value)?

Below method display the image with the text underneath the barcode..please advise

//Creates Audit barcode image without the message(barcode number).
        BarcodeInter25 audBarcode = new BarcodeInter25();
        audBarcode.setCode(123456789);

        Color black = new Color(0, 0, 0);
        Color white = new Color(255, 255, 255);
        Image audBarcodeImg = Image.getInstance(audBarcode.createImageWithBarcode(cb, null, null));
        audBarcodeImg.setRotationDegrees(-90);
        audBarcodeImg.setAbsolutePosition(18, 410);
        samplePdfDoc.add(123456789);
        audBarcode.setStartStopText(false);    

Upvotes: 0

Views: 1507

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77546

First two observations:

  1. You didn't copy/paste code that compiles. For instance: the setCode() needs a String not an int. You never add the barcode to samplePdfDoc and you can't add an int to samplePdfDoc...
  2. You are using an obsolete version of iText. That's a bad idea. See http://itextpdf.com/salesfaq for more info.

Now the solution: as documented in my book, you can remove the text by setting the font to null. I've taken your code and turned it into something that makes more sense:

Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
PdfContentByte cb = writer.getDirectContent();
BarcodeInter25 audBarcode = new BarcodeInter25();
audBarcode.setCode("0123456789");
audBarcode.setStartStopText(false); 
audBarcode.setFont(null);
Image audBarcodeImg = Image.getInstance(audBarcode.createImageWithBarcode(cb, null, null));
audBarcodeImg.setRotationDegrees(-90);
audBarcodeImg.setAbsolutePosition(18, 410);
document.add(audBarcodeImg);
document.close();

Now the code compiles, executes and shows the barcode without text. Please consider reading the documentation, and more importantly: please upgrade to the latest iText version as you're using a version that has been declared dead years ago.

Upvotes: 1

Related Questions