In This Topic
Programming / Barcode Reading & Writing / Recognizing DataMatrix barcodes within the first page of a PDF document

Recognizing DataMatrix barcodes within the first page of a PDF document

In This Topic

Recognizing DataMatrix barcodes using GdPicture is just like recognizing any other type of barcode. The methods have been designed to be identical in their usage, whether 1D, 2D, QR, MicroQR, or PDF714.

Here we open a PDF document, render the first page to an image and recognize the DataMatrix barcodes in it.

Copy Code
'We assume that GdPicture has been correctly installed and unlocked.
'Step1: Opening the PDF document.
Dim oGdPicturePDF As New GdPicturePDF()
If oGdPicturePDF.LoadFromFile("input.pdf", False) = GdPictureStatus.OK Then
    'Step2: Converting the desired page to GdPicture Image.
    oGdPicturePDF.SelectPage(1)
    Dim imageID As Integer = oGdPicturePDF.RenderPageToGdPictureImage(200, False)
    If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
        'Step3: Processing the barcode recognition from GdPicture Image.
        Dim oGdPictureImaging As New GdPictureImaging()
        If oGdPictureImaging.BarcodeDataMatrixReaderDoScan(imageID, BarcodeDataMatrixReaderScanMode.BestQuality) = GdPictureStatus.OK Then
            Dim barcodeCount As Integer = oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeCount()
            Dim message As String = "Number of DataMatrix barcodes: " + barcodeCount.ToString()
            For i As Integer = 1 To barcodeCount
                message = message + vbCrLf + "Barcode no: " + i.ToString() +
                          "    columns: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeColumns(i).ToString() +
                          "    rows: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeRows(i).ToString() +
                          "    value: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeValue(i)
            Next
            MessageBox.Show(message, "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("Error scanning a barcode: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        oGdPictureImaging.BarcodeDataMatrixReaderClear()
        oGdPictureImaging.ReleaseGdPictureImage(imageID)
        oGdPictureImaging.Dispose()
    Else
        MessageBox.Show("Error rendering an image: " + oGdPicturePDF.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If
End If
oGdPicturePDF.Dispose()
Copy Code
//We assume that GdPicture has been correctly installed and unlocked.
//Step1: Opening the PDF document.
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
if (oGdPicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
    //Step2: Converting the desired page to GdPicture Image.
    oGdPicturePDF.SelectPage(1);
    int imageID = oGdPicturePDF.RenderPageToGdPictureImage(200, false);
    if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
    {
        //Step3: Processing the barcode recognition from GdPicture Image.
        GdPictureImaging oGdPictureImaging = new GdPictureImaging();
        if (oGdPictureImaging.BarcodeDataMatrixReaderDoScan(imageID, BarcodeDataMatrixReaderScanMode.BestQuality) == GdPictureStatus.OK)
        {
            int barcodeCount = oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeCount();
            string message = "Number of DataMatrix barcodes: " + barcodeCount.ToString();
            for (int i = 1; i <= barcodeCount; i++)
            {
                message = message + "\nBarcode no: " + i.ToString() +
                          "    columns: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeColumns(i).ToString() + 
                          "    rows: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeRows(i).ToString() +
                          "    value: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeValue(i);
            }
            MessageBox.Show(message, "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
             MessageBox.Show("Error scanning a barcode: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        oGdPictureImaging.BarcodeDataMatrixReaderClear();
        oGdPictureImaging.ReleaseGdPictureImage(imageID);
        oGdPictureImaging.Dispose();
    }
    else
    {
        MessageBox.Show("Error rendering an image: " + oGdPicturePDF.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
oGdPicturePDF.Dispose();