Important alert: (current site time 5/24/2015 6:38:10 AM EDT)


Generate & Recognize Barcodes from PDF Documents in Java Applications

Submitted on: 2/8/2012 3:06:01 PM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 4417
     This technical tip shows how we can use Aspose.Pdf for Java to recognize barcodes from PDF documents.

Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

This technical tip shows how we can use Aspose.Pdf for Java to recognize barcodes from PDF documents.  First, we will use Aspose.BarCode for Java and generate a barcode image. We will save this image to a file on disk. Then, we will use Aspose.Pdf for Java to create Adobe PDF document and insert this barcode in that document. For the recognition part, we will first extract images from the PDF document using Aspose.Pdf.Kit for Java. Once images are extracted, we will pass these images to Aspose.BarCode for Java for barcode recognition. Below is the complete java program to generate and recognize barcodes from Adobe PDF documents:


import com.aspose.barcode.*;
import com.aspose.barcoderecognition.BarCodeReadType;
import com.aspose.barcoderecognition.BarCodeReader;
import com.aspose.pdf.elements.Pdf;
import com.aspose.pdf.elements.Section;
import com.aspose.pdf.kit.License;
import com.aspose.pdf.kit.PdfExtractor;
import java.awt.Toolkit;

public class RecognitionFromPdf
    public static void main(String[] args)
            // set license
            License licPdfKit = new License();
            FileInputStream stream = new FileInputStream("AsposeLicense.lic");

            com.aspose.barcode.License licBarCode = new com.aspose.barcode.License();

            String strPdfDoc = " output1.pdf";
            String strBarCodeImage = "";

            // generate barcode and add to pdf file
            BarCodeBuilder builder = new BarCodeBuilder();
            String strBarCodeImageSave = " img.jpg";
            //Instantiate a Pdf object by calling its empty constructor
            Pdf pdf1 = new Pdf();
            //Create a section in the Pdf object
            Section sec1 = pdf1.getSections().add();
            //Create an image object in the section
            com.aspose.pdf.elements.Image img1 = new com.aspose.pdf.elements.Image(sec1);
            //Add image object into the Paragraphs collection of the section
            //Set the path of image file
            img1.getImageInfo().setTitle("JPEG image");
            //Save the Pdf
            FileOutputStream out = new FileOutputStream(new File(strPdfDoc));

            //Instantiate PdfExtractor object
            PdfExtractor extractor = new PdfExtractor();

            //Bind the input PDF document to extractor

            //Extract images from the input PDF document
            String suffix = ".jpg";
            int imageCount = 1;
            while (extractor.hasNextImage()) {
                System.out.println("Extracting image " + imageCount);
                strBarCodeImage = "tmpbarcode" + imageCount + suffix;

                // recognize barcode from image
                BarCodeReader reader = new BarCodeReader(strBarCodeImage,BarCodeReadType.getCode39Standard());
                while (
                    System.out.println("codetext: " + reader.getCodeText());
        catch(Exception ex)

More about Aspose.BarCode for Java

  • Homepage of Aspose.BarCode for Java
  • Read more Technical Tips by Aspose.BarCode
  • Download of Aspose.BarCode for Java

Contact Information

Aspose Pty Ltd
Suite 163, 79 Longueville Road
Lane Cove, NSW, 2066
Aspose - Your File Format Experts

Phone: 888.277.6734
Fax: 866.810.9465

Other 48 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.