We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Barcode not getting detected in some PDF's

Hi ,

I am trying to create a POC using temporary liscence of Aspose total .Here Its workign fine for those PDF’s where the barcode is as an image . But its failing in some cases when its not an image file . Is there any possibility using aspose to cater the case when the PDF’s barcode is not an image ?
I tried using the version . Please let me know .


Hi Shilpi,

Thank you for your inquiry.

Please forward us the sample PDF that contains barcode which is not an image. We will analyze it and will update you accordingly.

I am sharing the code sample which I am using :

String savePath1 = @"\Upload";
barcodeReader.MediumTrustLevelCompatible = true;
barcodeReader.BarcodeTypesToFind.All = true;
Aspose.BarCode.License license = new Aspose.BarCode.License();
if (FileUploadControl.HasFile)

float distanceInPixelsFromLeft = 360;
float distanceInPixelsFromBottom = 30;
float width = 120;
float height = 80;

var rect1 = new System.util.RectangleJ(
String fileName = FileUploadControl.FileName;
savePath1 += fileName;

int c = GetNoOfPagesPDF(Server.MapPath(savePath1));
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Server.MapPath(savePath1));
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
// traverse through each image extracted from PDF pages
foreach (XImage xImage in pdfDocument.Pages[pageCount].Resources.Images)
using (MemoryStream imageStream = new MemoryStream())

//var bitmap = new BitmapImage();
// bitmap.BeginInit();
// bitmap.StreamSource = imageStream;
// bitmap.CacheOption = BitmapCacheOption.OnLoad;
// bitmap.EndInit();
// bitmap.Freeze();

//save output image
xImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Bmp);
// set the stream position to the begining of Stream
imageStream.Position = 0;
// Instantiate BarCodeReader object
// Aspose.BarCodeRecognition.BarCodeReader qq = new BarCodeReader(bitmap, rect1, BarCodeReadType.Pdf417);
Aspose.BarCodeRecognition.BarCodeReader barcodeReader1 = new Aspose.BarCodeRecognition.BarCodeReader(imageStream, Aspose.BarCodeRecognition.BarCodeReadType.Code39Standard
|BarCodeReadType.AllSupportedTypes | BarCodeReadType.AustralianPosteParcel | BarCodeReadType.AustraliaPost | BarCodeReadType.Aztec | BarCodeReadType.Codabar | BarCodeReadType.Code11 |
BarCodeReadType.Code128 | BarCodeReadType.Code16K | BarCodeReadType.Code39Extended | BarCodeReadType.Code93Extended | BarCodeReadType.Code93Standard | BarCodeReadType.CompactPdf417 |
BarCodeReadType.DatabarExpanded | BarCodeReadType.DatabarExpandedStacked | BarCodeReadType.DatabarLimited | BarCodeReadType.DatabarOmniDirectional |BarCodeReadType.DatabarStacked |BarCodeReadType.DatabarStackedOmniDirectional|BarCodeReadType.DatabarTruncated|BarCodeReadType.DataMatrix

while (barcodeReader1.Read())
// get BarCode text from BarCode image
string code = barcodeReader1.GetCodeText();
// write the BarCode text to Console output
if (code != null)
flag = 1;
// close BarCodeReader object to release the Image file


Note: I shall not be able to share the pdf document as its specific to the client and confidential .

But then the code fails in those pdf’s which does not has barcode as image and in embedded.
A quick reply shall be appreciated … I find myself stuck up in this case…

Please help


Hi Shilpi,
Thank you for providing code sample.
Please note that in case where barcode is not an image in the PDF file, you have to first convert the PDF pages to images and then read barcode. We are attaching the sample code snippet for your reference.

int pageIndex = 0;

// bind the pdf
PdfConverter converter = new PdfConverter();
converter.RenderingOptions.BarcodeOptimization = true;
while (converter.HasNextImage())
Console.WriteLine("Getting next Page...");
MemoryStream pageStream = new MemoryStream();
converter.GetNextImage(pageStream, ImageFormat.Png);
using (BarCodeReader reader = new BarCodeReader(pageStream, BarCodeReadType.EAN13))
while (reader.Read())
Console.WriteLine("Code Text: " + reader.GetCodeText() + " Type: " + reader.GetReadType());

Hope the above information helps. Feel free to contact us in case you have further query or comments along with the sample file. Please go through the EULA details, we are bound not to disclose any information that is private or confidential.

Hi ,

The sample code provided seems to work for me …

Thank You,

Hi Shilpi,

Thank you for the acknowledgement. We are glad to hear that your problem is resolved. Please continue using our API's and in the event of any further query, please feel free to contact us.