Help in reading barcode from PDF

1,779 views
Skip to first unread message

Rana

unread,
Mar 6, 2012, 2:51:59 PM3/6/12
to zxing
Hi,

I am trying to read barcode from scanned PDF...I am getting
NotFoundException.

My code is as below. I am using Apache PDFbox to convert PDF to image
file.

File pdfFile = new File("C:/scanned/Scan_000172.pdf");

Code128Reader reader = new Code128Reader();

InputStream input = new FileInputStream(pdfFile);

PDDocument testDoc = PDDocument.load(input);

List pages = testDoc.getDocumentCatalog().getAllPages();

for(int i=0; i<pages.size(); i++) {

PDPage page = (PDPage)pages.get(i);
BufferedImage image = page.convertToImage();
LuminanceSource source = new BufferedImageLuminanceSource(image);

BinaryBitmap bitmap = new BinaryBitmap(new
HybridBinarizer(source));

Result result = reader.decode(bitmap);

System.out.println(result.getText());

}

Sean Owen

unread,
Mar 6, 2012, 5:48:48 PM3/6/12
to zx...@googlegroups.com
You aren't necessarily doing anything wrong. It just means it didn't find the barcode in that image.

Rana

unread,
Mar 6, 2012, 6:10:31 PM3/6/12
to zxing
Thanks Sean for the response...We managed the issue by generating
barcode using QRCodeWriter of ZXing.
After that,when it comes to reading the same barcode... we changed our
code from Code128Reader to QRCodeMultiReader..That fixed the
problem...Please check code below.


File pdfFile = new File("C:/scanned/Scan_000177.pdf");

QRCodeMultiReader reader = new QRCodeMultiReader();
Result result=null;

FileInputStream input = new FileInputStream(pdfFile);
PDDocument testDoc = PDDocument.load(input);
List<PDPage> pages =
testDoc.getDocumentCatalog().getAllPages();

for(int i=0; i<pages.size(); i++) {

PDPage page = (PDPage)pages.get(i);
BufferedImage image = page.convertToImage();
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new
GlobalHistogramBinarizer(source));
result = reader.decode(bitmap);
}
System.out.println(result.getText());

Output is successfully printed in our console.

Currently this code is working fine for us, but i want to understand
why it didn't work for Code128Writer and Code128Reader(As posted in my
previous email above)
The data we try to encode in barcode is, 8135:Progress Notes:
03/05/2012

Sean Owen

unread,
Mar 7, 2012, 4:25:32 AM3/7/12
to zx...@googlegroups.com
I don't think this can be right. If it's a Code 128 code, QRCodeReader will definitely not read it. Something else is going on.
Reply all
Reply to author
Forward
0 new messages