Doing some testing here on Aspose.Barcode and trying to read from a stream which originates in an Amazon S3 bucket. If I use a local filename, it works fine. If I try and pass barCodeReader a stream, I get the following Barcodereader.JPG (76.1 KB)
Code is pretty simple and here for convenience as well as in the screenshot
AmazonS3Client client = new AmazonS3Client();
GetObjectRequest request = new GetObjectRequest();
request.BucketName = newdoc.BucketName;
request.Key = newdoc.ObjectKey;
GetObjectResponse response = client.GetObject(request);
Stream docStream = new MemoryStream();
response.ResponseStream.CopyTo(docStream);
BarCodeReader barCodeReader = new BarCodeReader(docStream, DecodeType.Code39Extended);
barCodeReader.RecognitionMode = RecognitionMode.MaxBarCodes;
while (barCodeReader.Read())
{
Console.WriteLine(barCodeReader.GetCodeText());
}
Any ideas ? I’m using v 17.6.0 installed via NuGet and a temporary license file.
There really isn’t any more to it than that - it just gets the S3 object defined by newdoc.BucketName and newdoc.ObjectKey… I can send you a project though please bear with me
I am happy to say that your suggestions helped to solve my problem . I changed it to save the file to disk first and I could see that it wasn’t a complete file so once that was fixed using your suggestion it works fine !
Am I correct in assuming that in order to read a barcode from a PDF I need to convert the pdf to an image (which I can also do in memory) and then pass that image to barcodereader ?
Thank you for your feedback. Yes, you are correct. You have to extract image from PDF document, save the extracted image as stream or on disk and then perform barcode recognition process in order to read the barcode from PDF document. Please visit the link Recognize Barcode from PDF Document for details.
Hello, sorry to trouble you again. I purchased the barcode component and I was just trying to finish this project using the referred article you sent me on extracting the image from the PDF. It wasn’t working so I simplified my code to just load the PDF from disk (rather than pulling the stream from S3) and save the image to disk (rather than passing the imagestream to barcodereader). Its saving a 0 byte image so something isn’t quite right. I’ve attached the pdf I need to read the barcode from . Any insights you can give would be most valuable.
We have evaluated the sample PDF. We are able to recognize the barcode using the latest version of Aspose.BarCode i.e. 17.8. Sample code snippet is given below for your reference.
CODE:
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(@"L126-20170918094127072.pdf");
// 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
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;
Console.WriteLine("Recognizing barcode....");
Aspose.BarCode.BarCodeRecognition.BarCodeReader barcodeReader =
new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream);
while (barcodeReader.Read())
{
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType().ToString());
}
// close the reader
barcodeReader.Close();