BarcodeInter25 extends Barcode1D { @Override public Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor) { String fullCode = code; float fontX = 0; if (font != null) { if (generateChecksum && checksumText) fullCode += getChecksum(fullCode); fontX = font.getWidth(fullCode = altText != null ? altText : fullCode, size); } String bCode = keepNumbers(code); if (generateChecksum) bCode += getChecksum(bCode); int len = bCode.length(); float fullWidth = len * (3 * x + 2 * x * n) + (6 + n) * x; float barStartX = 0; float textStartX = 0; switch (textAlignment) { case ALIGN_LEFT: break; case ALIGN_RIGHT: if (fontX > fullWidth) { barStartX = fontX - fullWidth; } else { textStartX = fullWidth - fontX; } break; default: if (fontX > fullWidth) { barStartX = (fontX - fullWidth) / 2; } else { textStartX = (fullWidth - fontX) / 2; } break; } float barStartY = 0; float textStartY = 0; if (font != null) { if (baseline <= 0) { textStartY = barHeight - baseline; } else { textStartY = -getDescender(); barStartY = textStartY + baseline; } } byte[] bars = getBarsInter25(bCode); boolean print = true; if (barColor != null) canvas.setFillColor(barColor); for (int k = 0; k < bars.length; ++k) { float w = (bars[k] == 0 ? x : x * n); if (print) { canvas.rectangle(barStartX, barStartY, w - inkSpreading, barHeight); } print = !print; barStartX += w; } canvas.fill(); if (font != null) { if (textColor != null) { canvas.setFillColor(textColor); } canvas.beginText(); canvas.setFontAndSize(font, size); canvas.setTextMatrix(textStartX, textStartY); canvas.showText(fullCode); canvas.endText(); } return getBarcodeSize(); } BarcodeInter25(PdfDocument document);  BarcodeInter25(PdfDocument document, PdfFont font); static String keepNumbers(String text); static char getChecksum(String text); static byte[] getBarsInter25(String text); @Override Rectangle getBarcodeSize(); @Override Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor); @Override Image createAwtImage(java.awt.Color foreground, java.awt.Color background);  }
@Test public void barcode01Test() throws IOException, PdfException, InterruptedException { String filename = "barcodeInter25.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument document = new PdfDocument(writer); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); Barcode1D barcode = new BarcodeInter25(document); barcode.setGenerateChecksum(true); barcode.setCode("41-1200076041-001"); barcode.setTextAlignment(Barcode1D.ALIGN_CENTER); barcode.placeBarcode(canvas, ColorConstants.BLUE, ColorConstants.GREEN); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }