BarcodeCodabar extends Barcode1D { public Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor) { String fullCode = code; if (generateChecksum && checksumText) { fullCode = calculateChecksum(code); } if (!startStopText) { fullCode = fullCode.substring(1, fullCode.length() - 1); } float fontX = 0; if (font != null) { fontX = font.getWidth(fullCode = altText != null ? altText : fullCode, size); } byte[] bars = getBarsCodabar(generateChecksum ? calculateChecksum(code) : code); int wide = 0; for (int k = 0; k < bars.length; ++k) { wide += bars[k]; } int narrow = bars.length - wide; float fullWidth = x * (narrow + wide * n); 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; } } 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(); } BarcodeCodabar(PdfDocument document);  BarcodeCodabar(PdfDocument document, PdfFont font); static byte[] getBarsCodabar(String text); static String calculateChecksum(String code); Rectangle getBarcodeSize(); Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor); java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background);  }
@Test public void barcode01Test() throws IOException, PdfException, InterruptedException { String filename = "codabar.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument document = new PdfDocument(writer); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); BarcodeCodabar codabar = new BarcodeCodabar(document); codabar.setCode("A123A"); codabar.setStartStopText(true); codabar.placeBarcode(canvas, null, null); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }