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

Recognizing QR codes within the first page of a PDF document

In This Topic

Recognizing QR codes 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 QR 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.BarcodeQRReaderDoScan(imageID, BarcodeQRReaderScanMode.BestQuality) = GdPictureStatus.OK Then
            Dim barcodeCount As Integer = oGdPictureImaging.BarcodeQRReaderGetBarcodeCount()
            Dim message As String = "Number of QR barcodes: " + barcodeCount.ToString()
            For i As Integer = 1 To barcodeCount
                message = message + vbCrLf + "Barcode no: " + i.ToString() +
                          "    version: " + oGdPictureImaging.BarcodeQRReaderGetVersion(i).ToString() +
                          "    value: " + oGdPictureImaging.BarcodeQRReaderGetBarcodeValue(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.BarcodeQRReaderClear()
        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.BarcodeQRReaderDoScan(imageID, BarcodeQRReaderScanMode.BestQuality) == GdPictureStatus.OK)
        {
            int barcodeCount = oGdPictureImaging.BarcodeQRReaderGetBarcodeCount();
            string message = "Number of QR barcodes: " + barcodeCount.ToString();
            for (int i = 1; i <= barcodeCount; i++)
            {
                message = message + "\nBarcode no: " + i.ToString() +
                          "    version: " + oGdPictureImaging.BarcodeQRReaderGetVersion(i).ToString() + 
                          "    value: " + oGdPictureImaging.BarcodeQRReaderGetBarcodeValue(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.BarcodeQRReaderClear();
        oGdPictureImaging.ReleaseGdPictureImage(imageID);
        oGdPictureImaging.Dispose();
    }
    else
    {
        MessageBox.Show("Error rendering an image: " + oGdPicturePDF.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
oGdPicturePDF.Dispose();