Barcode detecting only in the specific region on each page

Hi ,

I am trying to achieve the scenario where I need to detect barcode on each page at specific region of the PDF (rectagle area) .

I dont wish to scan the entire pdf file as its heavy and performance hit . Please advise .

Thanks,
Shilpi

Hi Shilpi,

Thank you for your inquiry.

Please note that you can use Aspose.Barcode to scan only a part of the image that contains barcode. For example you have an area of a rectangle i.e. (0, 0, 100, 50). The barcode reader will scan only the specified area and will be able to recognize the barcode. On the other hand, it will greatly increase the speed of recognition process, because the barcode reader will only look into the specified area and ignore rest of the image.

Following is the sample code snippet for your reference. For more information visit the link Read Barcode from Specific Region of Image.


// create an instance of BarCodeReader class
// and specify an area to look for the barcode
BarCodeReader reader = new BarCodeReader(new Bitmap("test.png"), new Rectangle(0, 0, 100, 50), BarCodeReadType.Pdf417);
// read all barcodes in the provided area
while (reader.Read() == true)
{
// display the codetext and symbology type of the barcode found
Console.WriteLine("Codetext: " + reader.GetCodeText() +
" Symbology: " + reader.GetReadType().ToString());
}
// close the reader
reader.Close();

Hope the above information helps. Feel free to contact us in case you have further comments or queries.

Hi ,

I completely agree with the solution provided , but will this handle for all the pages of the pdf ? How will we loop across all the pages ?

Actually I wanted to process around 60 pages and it a performance i hit as it keeps on processing . I want to eliminate this and ensure that all the pages are scanned up for pdf.

Thanks,
Shilpi

Hi Shilpi,

Thank you for writing us back.

Go through the article Recognize Barcode from Pdf Document to read barcode from all pages of PDF file. In case you face issue i.e. system keeps on processing or halts, please forward us your code and the PDF file containing 60 pages. We will look into the issue and will update you with our findings.

Hi ,

Please find the code as under:

int pageIndex = 0;

// bind the pdf
PdfConverter converter = new PdfConverter();
converter.BindPdf(Server.MapPath(savePath1));
converter.RenderingOptions.BarcodeOptimization = true;
converter.DoConvert();

while (converter.HasNextImage())
{
pageIndex++;
MemoryStream pageStream = new MemoryStream();
converter.GetNextImage(pageStream, ImageFormat.Png);
using (BarCodeReader reader1 = new BarCodeReader(new Bitmap(“test.png”), new System.Drawing.Rectangle(0, 0, 100, 50), BarCodeReadType.Pdf417))
{
while (reader1.Read())
{
flag = 1;
}
}

}

I am trying to read barcode from all the pages of the pdf at a specific region . I am getting the error" Parameter is not valid."

Please advise
Thanks,
Shilpi

Hi Shilpi,

Please forward us the PDF file that you are using. We will look into it and update you accordingly about our findings.

Hi ,
Please find the Sample Pdf which I am trying ot process , attached in the very first post.

Thanks,
Shilpi

Hi Shilpi,

Thank you for providing sample PDF.

Please note that we are able to notice the issue. Therefore the issue has been logged into our issue tracking system with ID BARCODENET-34336. Our product team will further look into it. We will update you accordingly via this post.

Hi ,

Is there any update on this ? I am kind of stuck up and looking for a quick resolution as the requirement of my application . I need to verify if aspose shall meet up the requirement .Please help me in this as I have to finalize with the tool .


Thanks,
Shilpi

Hi Shilpi,

Please note that we have requested our product team for an update on this issue. We will update you accordingly about the progress/update soon.

Hi Shilpi,

Thank you for being patient.

This is to update you that the issue you are facing will be fixed in the next release. However there is a workaround for the time being. Following is the code snippet for your reference that reads barcodes successfully on each page of the PDF provided by you.

// set the license for Aspose.BarCode for .NET and Aspose.Pdf for .NET components
Aspose.BarCode.License licenceBarCode = new Aspose.BarCode.License();
licenceBarCode.SetLicense(@"C:\xxx.lic");

Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
licensePdf.SetLicense(@"C:\xxx.lic");
// bind the pdf document
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(@"C:\Input\SamplePdf.pdf");
// set page range for image extraction
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 5;

// 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
Aspose.BarCodeRecognition.BarCodeReader barcodeReader =
new Aspose.BarCodeRecognition.BarCodeReader(imageStream);
Aspose.BarCodeRecognition.BarCodeReader.ProcessorSettings.UseAllCores = false;
Aspose.BarCodeRecognition.BarCodeReader.ProcessorSettings.UseOnlyThisCoresCount = 1;
while (barcodeReader.Read())
{
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());
}
// close the reader
barcodeReader.Close();
}

Output:

Extracting images.....

Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....

Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard

Hi ,

The solution provided by you shall work but will scan the extire pdf document from the top for the next image . This will show a performance hit when the document a is heavy pdf.

Is there a way to scan only the rectangular section of each pdf to improve performance? I am trying to upload a 50 pages pdf file.

Thanks,
Shilpi

Hi Shilpi,

Please use the following code to read barcode from specific region.

// set the license for Aspose.BarCode for .NET and Aspose.Pdf for .NET components
Aspose.BarCode.License licenceBarCode = new Aspose.BarCode.License();
licenceBarCode.SetLicense(@"C:\xxx.lic");

Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
licensePdf.SetLicense(@"C:\xxx.lic");
// bind the pdf document
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(@"C:\Input\SamplePdf.pdf");
// set page range for image extraction
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 5;

// 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....");

Bitmap objBitmap = new System.Drawing.Bitmap(imageStream);
// recognize the barcode from the image stream above
Aspose.BarCodeRecognition.BarCodeReader barcodeReader =
new Aspose.BarCodeRecognition.BarCodeReader(objBitmap, new System.Drawing.Rectangle(1657, 2747, 577, 205), Aspose.BarCodeRecognition.BarCodeReadType.Code39Standard);
Aspose.BarCodeRecognition.BarCodeReader.ProcessorSettings.UseAllCores = false;
Aspose.BarCodeRecognition.BarCodeReader.ProcessorSettings.UseOnlyThisCoresCount = 1;
while (barcodeReader.Read())
{
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());
}
// close the reader
barcodeReader.Close();
}

Output:

Extracting images.....

Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....

Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard
Getting next image....
Recognizing barcode....
Codetext found: TEST8052, Symbology: Code39Standard

Hi ,

Yes I am able to achieve it through the code provided . This workaround seems to work fine for me. By when can I expect the fix of the issue in the upcoming release ?

If I pruchase the product from Aspose now, can the fix of the issue in the upcoming release be integrated in my application later on without any hussle and additional overhead?


Thanks,
Shilpi

Hi Shilpi,

Thanks for the acknowledgement.

Please note that our product team is making progress on this issue and a fix will be available soon. You will be intimated via this thread. Further, the fix will work perfectly for you and without hassle. In case you face any issue, we are here to assist you.

Hope the above information helps. Feel free to contact us in case you have further query or comments.

The issues you have found earlier (filed as BARCODENET-34336) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.