Scanning Barcode

Scanning Barcode in Java

GroupDocs.Parser, a Java API (which is a part of Conholdate.Total for Java) allows to extract barcodes from documents by the GetBarcodes method:

Iterable<PageBarcodeArea> getBarcodes()

This method returns a collection of PageBarcodeArea objects:

Member Description
Page The page that contains the text area.
Rectangle The rectangular area on the page that contains the text area.
Value A string value that represents a value of the barcode page area.
CodeTypeName A string value than represents a type name of the barcode.

Here are the steps to extract all barcodes from the whole document:

  • Instantiate Parser object for the initial document;
  • Check if the document 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 extract barcodes from a document:

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

	// Extract barcodes from the document.
	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 value
		System.out.println("Value: " + barcode.getValue());
	}
}