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

Recognizing PDF417 barcodes within the first page of a PDF document

In This Topic

Recognizing PDF417 barcodes using GdPicture is just like recognizing any other type of barcode. The methods were 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 PDF417 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.BarcodePDF417ReaderDoScan(imageID, BarcodePDF417ReaderScanMode.BestQuality) = GdPictureStatus.OK Then
            Dim barcodeCount As Integer = oGdPictureImaging.BarcodePDF417ReaderGetBarcodeCount()
            Dim message As String = "Number of PDF417 barcodes: " + barcodeCount.ToString()
            For i As Integer = 1 To barcodeCount
                message = message + vbCrLf + "Barcode no: " + i.ToString() +
                          "    columns: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeColumns(i).ToString() +
                          "    rows: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeRows(i).ToString() +
                          "    value: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeValue(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.BarcodePDF417ReaderClear()
        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.BarcodePDF417ReaderDoScan(imageID, BarcodePDF417ReaderScanMode.BestQuality) == GdPictureStatus.OK)
        {
            int barcodeCount = oGdPictureImaging.BarcodePDF417ReaderGetBarcodeCount();
            string message = "Number of PDF417 barcodes: " + barcodeCount.ToString();
            for (int i = 1; i <= barcodeCount; i++)
            {
                message = message + "\nBarcode no: " + i.ToString() +
                          "    columns: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeColumns(i).ToString() +
                          "    rows: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeRows(i).ToString() +
                          "    value: " + oGdPictureImaging.BarcodePDF417ReaderGetBarcodeValue(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.BarcodePDF417ReaderClear();
        oGdPictureImaging.ReleaseGdPictureImage(imageID);
        oGdPictureImaging.Dispose();
    }
    else
    {
        MessageBox.Show("Error rendering an image: " + oGdPicturePDF.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
oGdPicturePDF.Dispose();