Hi @amjad.sahi,
After meticulously reviewing the reference you mentioned and trying each of suggested methods, we regret to inform you that still we are facing same issue i.e. Parameter is not valid.
We have attempted multiple approaches, but unfortunately, result remains the same.
We kindly request your assistance in conducting in-more depth analysis to identify the root cause of problem and appropriate solution for this.
Please find the below approaches performed to achieve this.
Approach 1:
using (BarCodeReader read = new BarCodeReader(inputPath, DecodeType.Code39Standard, DecodeType.Code39Extended))
{
read.QualitySettings.AllowSaltAndPaperFiltering = true;
MessageBox.Show($“Barcodes read: {read.ReadBarCodes().Length}”);
foreach (BarCodeResult result in read.FoundBarCodes)
MessageBox.Show($"{result.CodeTypeName}:{result.CodeText}");
}
Approach 2:
using (BarCodeReader read = new BarCodeReader(inputPath, DecodeType.Code39Standard, DecodeType.Code39Extended))
{
read.QualitySettings.AllowSaltAndPaperFiltering = false;
MessageBox.Show($“Barcodes read: {read.ReadBarCodes().Length}”);
foreach (BarCodeResult result in read.FoundBarCodes)
MessageBox.Show($"{result.CodeTypeName}:{result.CodeText}");
}
Approach 3:
using (BarCodeReader read = new BarCodeReader(inputPath, DecodeType.Code128,
DecodeType.Code39Extended, DecodeType.Planet, DecodeType.QR,
DecodeType.MicroQR, DecodeType.Pdf417, DecodeType.DataMatrix, DecodeType.Aztec))
{
read.QualitySettings = QualitySettings.MaxBarCodes;
foreach (BarCodeResult result in read.FoundBarCodes)
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
Approach 4:
using (Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(inputPath))
{
Aspose.Pdf.Facades.PdfConverter pdfConverter = new Aspose.Pdf.Facades.PdfConverter(pdfDoc);
pdfConverter.RenderingOptions.BarcodeOptimization = true;
//set resolution to the page
//300 dpi is standard resolution
pdfConverter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
//set all pages to render into images
pdfConverter.StartPage = 1;//starts from 1
pdfConverter.EndPage = pdfConverter.Document.Pages.Count;
//render selected pages to the images
pdfConverter.DoConvert();
while (pdfConverter.HasNextImage())
{
//render current page to memory stream as png image
MemoryStream ms = new MemoryStream();
pdfConverter.GetNextImage(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;
//recognize Pdf417, QR and DataMatrix barcode types from rendered image of the page
BarCodeReader reader = new BarCodeReader(ms, DecodeType.Pdf417, DecodeType.QR, DecodeType.DataMatrix);
foreach (BarCodeResult result in reader.ReadBarCodes())
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
}
Approach 5:
using (Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(inputPath))
{
//process all PDF pages in the document, page numeration starts from 1
for (int i = 1; i <= pdfDoc.Pages.Count; ++i)
{
//create an image extractor and bind it to the page
Aspose.Pdf.ImagePlacementAbsorber imagePlacementAbsorber = new Aspose.Pdf.ImagePlacementAbsorber();
imagePlacementAbsorber.Visit(pdfDoc.Pages[i]);
//extract all images from the PDF page
foreach (Aspose.Pdf.ImagePlacement imagePlacement in imagePlacementAbsorber.ImagePlacements)
{
//convert an image from the pdf page to the stream
MemoryStream ms = new MemoryStream();
imagePlacement.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;
//recognize Pdf417, QR, and DataMatrix barcode types from extracted images from the page
BarCodeReader reader = new BarCodeReader(ms, DecodeType.Pdf417, DecodeType.QR, DecodeType.DataMatrix);
foreach (BarCodeResult result in reader.ReadBarCodes())
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
}
}
Approach 6:
using (Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(inputPath))
{
//create png device with 300 dpi standard resolution
Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(new Aspose.Pdf.Devices.Resolution(300));
//proceed all pdf pages, pages start from 1
for (int i = 1; i <= pdfDoc.Pages.Count; ++i)
{
//render pdf page to the stream
MemoryStream ms = new MemoryStream();
pngDevice.Process(pdfDoc.Pages[i], ms);
ms.Position = 0;
//recognize Pdf417, QR and DataMatrix barcode types from rendered image of the page
BarCodeReader reader = new BarCodeReader(ms, DecodeType.Pdf417, DecodeType.QR, DecodeType.DataMatrix);
foreach (BarCodeResult result in reader.ReadBarCodes())
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
}
Approach 7:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inputPath);
TextAbsorber textAbsorber = new TextAbsorber();
pdfDocument.Pages.Accept(textAbsorber);
string pdfText = textAbsorber.Text;
Bitmap bitmap = new Bitmap(1, 1);
Graphics graphics = Graphics.FromImage(bitmap);
SizeF size = graphics.MeasureString(pdfText, new System.Drawing.Font("Arial", 12)); // Adjust font and size as needed
bitmap.Dispose();
bitmap = new Bitmap((int)size.Width, (int)size.Height);
graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
graphics.DrawString(pdfText, new System.Drawing.Font("Arial", 12), Brushes.Black, PointF.Empty);
using (var barcodeReader = new BarCodeReader())
{
barcodeReader.SetBarCodeImage(bitmap);
foreach (BarCodeResult result in barcodeReader.ReadBarCodes())
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
Approach 8:
using (BarCodeReader reader = new BarCodeReader(inputPath, DecodeType.Code39Standard, DecodeType.Code128))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
MessageBox.Show("BarCode CodeText: " + result.CodeText);
}
Thanks,
Saurabh