Reputation: 53
I have tried to generate the Barcode128
barcode to be placed on label and usually labels are less width. I am wondering that 3 digit(100)
String barcode width is larger than 4 digit(1001)
string barcode. 3 digit barcode
should be less than the 4 digit barcode right? I have verified in online barcode generation 3 digit barcode
width is less than the 4 digit barcode width where as iText api takes width more for 3 digit
string compared to 4 digit string
.
Could anybody please let us know the reason for this and how to make 3 digit barcode shorter than the 4 digit barcode?
Online barcode generator URL here
Code sample used to generate the barcode.
Barcode128 code128 = new Barcode128();
code128.setCode(myText);
Image myBarCodeImage128 = code128.createImageWithBarcode(contentByte,
null, null);
then image is added to pdf document.
Upvotes: 1
Views: 1374
Reputation: 22963
Find a working snippet based on the answer from Paulo Soares.
Document document = new Document(new Rectangle(340, 842));
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("barcodes.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
document.add(new Paragraph("Barcode 128 demo"));
Barcode128 code128 = new Barcode128();
code128.setCode("100");
code128.setCodeSet(Barcode128CodeSet.B);
document.add(code128.createImageWithBarcode(cb, null, null));
code128 = new Barcode128();
code128.setCode("1001");
code128.setCodeSet(Barcode128CodeSet.B);
document.add(code128.createImageWithBarcode(cb, null, null));
document.close();
Upvotes: 1
Reputation: 1916
Barcode 128 has several ways to encode digits. One of the ways is to encode 2 digits in the same symbol. In 4 digit case case you have two symbols each with two digits, two symbols in total. In the 3 digit case you have a symbol for two digits, a symbol to switch to alphanumeric and symbol for the last digit, three symbols in total. As you can see, less is more in this case.
Upvotes: 5