Reputation: 99
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
Reputation: 77546
First two observations:
setCode()
needs a String
not an int
. You never add the barcode to samplePdfDoc
and you can't add an int
to samplePdfDoc
...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