简体   繁体   中英

Read barcode from PDF file

Is there any Java API around that can find a bar code inside an opened file (scanned PDF) and then retrieve the data from the bar code? Or how should I solve this problem?

If you're running on Windows, the ClearImage Barcode SDK has a Java API. It can read and decode barcodes from PDFs or images and provide the decoded data to you.

Some sample code:

public static void testDataMatrix () {
  try { 
       String filename  = "1.png ";
       CiServer objCi = new CiServer();
       Ci = objCi.getICiServer();

       ICiDataMatrix reader = Ci.CreateDataMatrix(); // read DataMatrix Barcode
       reader.getImage().Open(filename, 1);
       int n = reader.Find(0); // find all the barcodes in the doc
       for (i = 1; i <= n; i++) {
          ICiBarcode Bc = reader.getBarcodes().getItem(i); // getItem is 1-based
          System.out.println("Barcode " + i + " has Text: " + Bc.getText());
       }
   } catch (Exception ex) {System.out.println(ex.getMessage());}
 }

Another one to consider is Accusoft's Barcode Xpress which also has a Java API.

Disclaimer: I've done some work for Inlite in the past.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM