Scan Barcode

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

GroupDocs.Parser’s barcode 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 the simplest scenario - read barcodes from any supported format without additional settings (to resolve complex scenarios see advanced usage section).

How to scan barcode in Java with GroupDocs.Parser

To scan barcodes from your file, simply call getBarcodes method:

Iterable<PageBarcodeArea> getBarcodes()

This method returns a collection of PageBarcodeArea objects.

Here are the steps to extract barcodes from a file:

  • Instantiate Parser object for the initial file;
  • Check if the file supports barcodes extraction;
  • Call getBarcodes method and obtain collection of PageBarcodeArea objects;
  • Iterate through the collection and get a barcode value.

The following example shows how to scan barcodes:

// 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;
    }

    // Scan barcodes from the file
    Iterable<PageBarcodeArea> barcodes = parser.getBarcodes();

    // Iterate over barcodes
    for (PageBarcodeArea barcode : barcodes) {
        // Print the page index
        System.out.println("Page: " + barcode.getPage().getIndex());
        // Print the barcode type and value
        System.out.println(barcode.getCodeTypeName() + ": " + 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 Barcode Scanner App

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

You are welcome to scan barcode from your files or mobile phone camera 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.