Not able to extract barcode

I am able not able to get barcode from the attached pdf file. kindly revert soon.

Hi Shubham,

Sorry, I was not able to reproduce the issue using the latest version of Aspose.Barcode for Java i.e. 7.4.0. Can you please try the following code with the latest version and share your results? Please also share if you are using an older version.

Document pdfDocument = new Document("Transfer+Out+14pt+first+page+only+barcode.pdf");
int j = 1;
//Extract a particular image
for (com.aspose.pdf.XImage xImage : (Iterable)pdfDocument.getPages().get_Item(1).getResources().getImages())
{

java.io.OutputStream output = new java.io.FileOutputStream("Image1.jpg");

// Save the output image
xImage.save (output);
BarCodeReader reader = new BarCodeReader("Image1.jpg", BarCodeReadType.AllSupportedTypes);
reader.setRecognitionMode(RecognitionMode.MaxBarCodes);
while (reader.read())
{

System.out.println(reader.getCodeText());
System.out.println("IsDeniable: " + reader.getIsDeniable());

}
reader.close();
output.close();
j++;

}

Best Regards,

would you provide me the understanding of this code so that i can have better understanding to how to use code and which function and when…i appreciate your effort.

E.G: setRecognitionMode???
MaxBarCodes???
getIsDeniable??
pdfDocument.getPages().get_Item(1).getResources().getImages()???

to search whole pdf document i have to pass my variable in place of get_Item(1) as get_Item(j)??

Actaully i was using correct jar version but the code that you provided on your site :


PdfExtractor extractor = new PdfExtractor();

//Bind the input PDF document to extractor
extractor.bindPdf(pdfDocument);

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

// Recognize barcode from image
BarCodeReader reader = new BarCodeReader(strBarCodeImage,BarCodeReadType.AllSupportedTypes);
while (reader.read())
{
System.out.println("codetext: " + reader.getCodeText());
}
imageCount++;
reader.close();
}

Hi Shubham,

As far as your code is concerned, you can keep using that code. The only addition required in that code is setRecognitionMode, you can set it to MaxBarCodes to extract maximum possible barcodes. You can set different recognition modes according to your requirement e.g. if your barcodes have good quality and size, then you can use MaxPerformance to get more recognition speed. In case of MaxBarCodes, recognition speed will be slow but you will be able to read smaller size (as in your case) and low quality barcodes.

getIsDeniable is not required in your case however it can be used to check if a barcode was recognized properly or not. It can be useful in case of incorrect barcodes.

Regarding getPages().get_Item(1), I had used 1 to search first page only. Yes, you can use a variable like 'j' to search all PDF pages for images.

Best Regards,

i used the code shared by you as mentioned above and get value “61238” from barcode but value should be “sys”.please find attached pdf and revert. i am facing this issue with code39standard barcode as i am using AllSupportedTypes in the code and getting numerical value and if i am using code39standard in the code i am getting nothing from the barcode.

Hi Shubham,

We are investigating your input PDF and will update you shortly.

Best Regards,

please revert soon as i am facing this problem with many more cases.

Hi Shubham,

If you extract the image from PDF, you will notice that the barcode image has a very poor quality so it is not read. A new issue to read barcodes from such images has been logged into our issue tracking system as BARCODJAVA-33599. We will keep you updated on this issue in this thread.

Best Regards,

Dear Concern,

many of the utilities provided online can easily extract the barcode from the provided pdf. kindly resolve the issue soon.

Hi Shubham,

Priority of this issue has been raised. We will try to resolve it soon. Sorry for the inconvenience.

Best Regards,

Problem exists in incorrect usage of Aspose PDF which generates unrecognizable by anyone barcode product images.

Here is C# code which helps to generate proper image which is recognized well.

You also can simplify the code and load stream to barcode reader without converting it to bitmap. If you want all images are recognized well you should use 300 dpi as in "Aspose.Pdf.Devices.Resolution(300);" row.

protected Bitmap PDFToBitmap(string Filename, int Page)
{
    Bitmap lResImage = null;
    try
    {
    <span class="code-comment">//create pdf document from file or from any other source

Aspose.Pdf.Document lPdfDoc = new Aspose.Pdf.Document(Filename);
if ((Page < 1) || (lPdfDoc.Pages.Count < Page)) return null;

    <span class="code-comment">//create pdf converter

Aspose.Pdf.Facades.PdfConverter lPdfConverter = new Aspose.Pdf.Facades.PdfConverter(lPdfDoc);
//create resolution of the page
//300 dpi is standard resolution
lPdfConverter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
//start and end page set to the required page
lPdfConverter.StartPage = Page;
lPdfConverter.EndPage = Page;
//convert our pdf to image
lPdfConverter.DoConvert();

    <span class="code-comment">// Create a MemoryStream object to hold the resultant image

MemoryStream lResStream = new MemoryStream();
//check if we have the image
if (lPdfConverter.HasNextImage())
{
//save image to stream
lPdfConverter.GetNextImage(lResStream, System.Drawing.Imaging.ImageFormat.Png);
lResStream.Position = 0;
//read the image to Bitmap
lResImage = new Bitmap(lResStream);
}
return lResImage;
}
catch(Exception e)
{
return null;
}
}

Hi Shubham,

Thank you for update. It is good to know that you are able to resolve the issue. The information has been shared with our product team. They will further look into it.