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

Barcode 2of5 

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 CODE 2of5 Barcode.

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

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

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.BarcodeInter25;
import com.itextpdf.text.pdf.PdfWriter;

public class BarCode2of5Test {

  /**
   @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("2of5.pdf"));
    document.open();

    //Barcode 2 of 5
    document.add(new Paragraph("Barcode Interleaved 2 of 5"));
        BarcodeInter25 code25 = new BarcodeInter25();
        code25.setGenerateChecksum(true);
        code25.setCode("21-6208246041-001");
        
        //Add Barcode to PDF document
        document.add(code25.createImageWithBarcode(writer.getDirectContent(), null, null));
        
        code25.setCode("0123456785678");
        code25.setChecksumText(true);
        
        //Add Barcode to PDF document
        document.add(code25.createImageWithBarcode(writer.getDirectContent(), null, null));
        document.close();
  }

}
   

It gives the following output,

CODE 2of5 Barcode



 
  


  
bl  br