How to read attached barcode in pdf file
Sample pdf file attachedABN34213.pdf (357.1 KB)
@bilbi_citrus,
You may try the following sample code and share the feedback.
try
{
// Bind the pdf document
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(@"ABN34213.pdf");
// Set page range for image extraction
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 2;
// 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
using (BarCodeReader reader = new BarCodeReader(imageStream, DecodeType.Code128))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Codetext found: " + result.CodeType + ", Symbology: " + result.CodeText);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}