Use BarcodeEAN : BarcodeEAN « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {

  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(
        "2.pdf"));
    document.open();

    PdfContentByte cb = writer.getDirectContent();
    BarcodeEAN codeEAN = new BarcodeEAN();
    codeEAN.setCode("4512345678906");
    Paragraph p = new Paragraph();
    p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0, -5));
    codeEAN.setGuardBars(false);
    document.add(p);
    document.close();
  }
}








29.69.BarcodeEAN
29.69.1.Use BarcodeEAN
29.69.2.BarcodeEAN Without Guard bars
29.69.3.Set text above for BarcodeEAN