Hi,
I need to read barcodes from a pdf document.
I read from your documentation that I must extract images from the pdf document and process them with the BarCodeReader object.
But, unfortunately, this way does’nt work for some barcodes.
Please check the attached document.
Why the barcode was not found?
My test code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Pdf.Kit;
using System.IO;
using Aspose.BarCodeRecognition;
namespace ConsoleApplication1 {
class Program {
const string ASPOSE_LIC_PATH = “Aspose.Total.lic”;
static void Main(string[] args) {
try {
// set the license for Aspose.BarCode for .NET and Aspose.Pdf.Kit for .NET components
Aspose.BarCodeRecognition.License licenceBarCodeRecognition = new Aspose.BarCodeRecognition.License();
licenceBarCodeRecognition.SetLicense(ASPOSE_LIC_PATH);
Aspose.Pdf.Kit.License licensePdfKit = new Aspose.Pdf.Kit.License();
licensePdfKit.SetLicense(ASPOSE_LIC_PATH);
// bind the pdf document
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.BindPdf(@“FATTP00000000005.pdf”);
// set page range for image extraction
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 1;
// extract the images
Console.WriteLine(“Extracting images…”);
pdfExtractor.ExtractImage();
// save images to stream in a loop
while (pdfExtractor.HasNextImage()) {
Console.WriteLine(“Getting next image…”);
// save image to stream
MemoryStream imageStream = new MemoryStream();
pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;
Console.WriteLine(“Recognizing barcode…”);
// recognize the barcode from the image stream above
BarCodeReader barcodeReader = new BarCodeReader(imageStream, BarCodeReadType.Code128);
while (barcodeReader.Read()) {
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());
}
// close the reader
barcodeReader.Close();
}
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
Console.WriteLine(“Press Return to terminate”);
Console.ReadLine();
}
}
}
Hi, I’ve noticed that with an older version of the barcode libraries the barcode was readed!!
The old version I’ve tried is the 4.1.0.0 both for Aspose.BarCodeRecognition.dll and Aspose.BarCode.dll.
My current version is the 4.5.0.0 (for both libraries).
Is tihs a new bug introdiced with latest versions?
Can I use old libraries without any risk?
Hi Alessandro,
Hi,
Hi Jason,
Hi,
I’ve found some others problems with pdf documents.
Please see the attached PDF document: I’ cannot read the EAN13 barcode inside.
This is my code (using Aspose.BarCode 4.1.0.0 and Aspose.BarCodeRecognition 4.1.0.0):
static void testReadFromPDF () {
try {
// set the license for Aspose.BarCode for .NET and Aspose.Pdf.Kit for .NET components
Aspose.BarCodeRecognition.License licenceBarCodeRecognition = new Aspose.BarCodeRecognition.License();
licenceBarCodeRecognition.SetLicense(ASPOSE_LIC_PATH);
Aspose.Pdf.Kit.License licensePdfKit = new Aspose.Pdf.Kit.License();
licensePdfKit.SetLicense(ASPOSE_LIC_PATH);
// bind the pdf document
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.BindPdf(@“document1.pdf”);
// set page range for image extraction
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 1;
// extract the images
Console.WriteLine(“Extracting images…”);
pdfExtractor.ExtractImage();
// save images to stream in a loop
while (pdfExtractor.HasNextImage()) {
Console.WriteLine(“Getting next image…”);
// save image to stream
MemoryStream imageStream = new MemoryStream();
pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;
Console.WriteLine(“Recognizing barcode…”);
// recognize the barcode from the image stream above
BarCodeReader barcodeReader = new BarCodeReader(imageStream, BarCodeReadType.EAN128);
while (barcodeReader.Read()) {
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());
}
// close the reader
barcodeReader.Close();
}
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
Console.WriteLine(“Press Return to terminate”);
Console.ReadLine();
}
Any help?
Hi,
Hi, thank you for your support.
I’ve tested the new DLLs (4.5.0.1) and they are ok whith my document1.pdf.
But now I’m testing your DLLs over various document to find other issues.
Now I’ve problems with the new attached document.
The code is the same as previous (only replace BarCodeReadType.EAN13 with BarCodeReadType.Code128), and the problem is that the found barcode is incorrect because it has an initial “f” character:
Codetext found: fD00000001863, Symbology: Code128
Any suggestions?
I’m a little worried about your libraries… because my application is based on your libraries for writing and reading barcodes and then it is very important for me that they work correctly!
Hi,
I’ve generated the barcode with the Aspose.BarCode.BarCodeBuilder but then I’ve printed the document using PDFCreator.
Hi,
Hi, I’m not able to give you my code to generate the file, as I said,
the file was generated by printing the image on PDFCreator.
But I
think that the problem is on the recognition library, because I can
easily read the barcode on the file by other apps (for example a simple
barcode reader on my iphone, reading through the monitor!).
I’ve created a new private post with an attached file, that is confidential.
The attached file has a barcode that I cannot read with aspose
libraries (both with 4.1.0.0 and 4.5.0.1 versions). This file is
generated by one of our customers, with its ERP.
Even in this case I can read the barcode with my iphone simple app!
The link to the post is:
https://forum.aspose.com/t/another-file-with-barcode-that-cannot-be-read/16327
Thank you for your support.
Hi,
The issues you have found earlier (filed as BARCODENET-33143) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.