Free Support Forum -

Not reading DataMatrix barcode in PDF

I am seeing intermittent issues with reading DataMatrix style barcodes within a pdf.

Attached are a couple of sample documents that have a barcode, and below is the code I am using to read these barcodes.

Any help on figuring out why I can’t recognize barcodes in these particular pdf’s would be appreciated.

//Sample Code

extractor.StartPage = 1;
            <span style="color:#2b91af;">MemoryStream</span> stream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
            stream.Position = 0;
            <span style="color:#2b91af;">BarCodeReader</span> barCodeReader = <span style="color:blue;">new</span> <span style="color:#2b91af;">BarCodeReader</span>(<span style="color:blue;">new</span> <span style="color:#2b91af;">Bitmap</span>(stream), <span style="color:#2b91af;">BarCodeReadType</span>.DataMatrix);
            <span style="color:green;">//Only read the first barcode on the page.  If they put more than 1 barcode on a page, well, too bad.</span>
            <span style="color:blue;">if</span> (barCodeReader.Read()) {
                <span style="color:blue;">string</span> barcodeText = barCodeReader.GetCodeText();<br>                }<br></pre><br>Let me know if you have any questions or need additional information.<br><br><br>


Thank you for inquiry.

Could you please check with the latest version of Aspose.BarCode for .NET? I tried to read barcodes from the attached documents with the same code and it did read the datamatrix barcodes correctly. Below is my complete code

PdfExtractor extractor = new PdfExtractor();
extractor.StartPage = 1;

MemoryStream stream = new MemoryStream();
stream.Position = 0;
BarCodeReader barCodeReader = new BarCodeReader(new Bitmap(stream), BarCodeReadType.DataMatrix);
//Only read the first barcode on the page. If they put more than 1 barcode on a page, well, too bad.
if (barCodeReader.Read())
string barcodeText = barCodeReader.GetCodeText();

Why BarCodeReadType.DataMatrix give me error?

Hi Marco,

Thanks for the inquiry and sorry for delayed response. First off, please try to use the latest Aspose.BarCode v5.0 at your end and see if it resolves your issue. If it still doesn’t resolve your issue then please share input documents here in this thread. We’ll take a closer look and guide you accordingly.

I hope this will help.