tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Barcodes > iText > Barcode EAN

Barcode EAN 

iText is a free and open source library for creating PDF documents and generating Barcodes in Java. This requires the library iText-5.0.2.jar to be in classpath. The following example shows generating EAN13 Barcode.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.itext;


import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BarcodeEAN;
import com.itextpdf.text.pdf.PdfWriter;

public class BarCodeEANTest {

   @param args
   @throws DocumentException 
   @throws FileNotFoundException 
  public static void main(String[] argsthrows FileNotFoundException, DocumentException {
    Document document = new Document(new Rectangle(PageSize.A4));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ean13.pdf"));;

    //Barcode EAN 13
    document.add(new Paragraph("Barcode EAN-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();
    //Add Barcode to PDF document
    document.add(codeEAN.createImageWithBarcode(writer.getDirectContent(), null, null));


It gives the following output,

EAN13 Barcode


bl  br