Scan QR Code

GroupDocs.Parser for Java allows to scan QR Codes from PDF, MS Word (DOC, DOCX), MS PowerPoint (PPT, PPTX), LibreOffice formats, images and many others (see full list at supported document formats article).

GroupDocs.Parser’s QR Code scanner is easy to use and powerful at the same time. Its algorithms allow to read even damaged barcodes.

This article demonstrates how to implement QR Code reader for any supported format.

How to scan QR Code in Java with GroupDocs.Parser

To scan QR Codes from your file, call getBarcodes(BarcodeOptions) method with BarcodeOptions that restrict the barcode types to "QR":

Iterable<PageBarcodeArea> getBarcodes(BarcodeOptions options)

This method returns a collection of PageBarcodeArea objects.

Here are the steps to extract QR Codes from a file:

The following example shows how to scan QR Codes:

// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SamplePdfWithBarcodes)) {
    // Check if the file supports barcodes extraction
    if (!parser.getFeatures().isBarcodes()) {
        System.out.println("The file doesn't support barcodes extraction.");
        return;
    }

    // Create the options to scan barcodes with "QR" type only
    BarcodeOptions options = new BarcodeOptions(QualityMode.Low, QualityMode.Low, "QR");

    // Scan QR Codes from the file
    Iterable<PageBarcodeArea> qrcodes = parser.getBarcodes(options);

    // Iterate over QR Codes
    for (PageBarcodeArea qrcode : qrcodes) {
        // Print the page index
        System.out.println("Page: " + qrcode.getPage().getIndex());
        // Print the QR Code value
        System.out.println("Value: " + qrcode.getValue());
    }
}

Alternatively, scan all barcodes with getBarcodes() and keep the ones whose getCodeTypeName method returns "QR":

// Iterate over all barcodes
for (PageBarcodeArea barcode : parser.getBarcodes()) {
    // Skip barcodes of other types
    if (!"QR".equals(barcode.getCodeTypeName())) {
        continue;
    }
    // Print the QR Code value
    System.out.println("Value: " + barcode.getValue());
}

More resources

Advanced usage topics

To learn more about scan barcode features, please refer the advanced usage section.

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online QR Code Scanner App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to scan QR Code from your file with our free online GroupDocs Scanner App which is built with GroupDocs.Parser.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.