Search for Barcode e-Signatures

GroupDocs.Signature provides the ability to search for barcode signatures in documents. Barcode signatures can be used to store various types of information in a compact format.

What is a Barcode Signature?

A barcode signature is a visual representation of data that can be scanned and read by machines. It typically consists of parallel black lines and white spaces of varying widths. Barcodes are commonly used for:

  • Product identification
  • Inventory tracking
  • Document verification
  • Data encoding

How to Search for Barcode Signatures

The Signature class provides the search method which allows you to search for barcode signatures in documents. Here’s how to use it:

  1. Create a new instance of the Signature class and pass the source document path as a parameter.
  2. Instantiate the BarcodeSearchOptions object with the required options.
  3. Call the search method of the Signature class instance and pass a list with the BarcodeSearchOptions to it.
  4. Process the search results: the signatures property of the returned SearchResult holds the found BarcodeSignature objects.

Here’s an example of how to search for barcode signatures in a document:

from groupdocs.signature import Signature
from groupdocs.signature.options import BarcodeSearchOptions

def search_barcodes():
    with Signature("signed.pdf") as signature:
        # Search all pages of the document for barcode signatures
        result = signature.search([BarcodeSearchOptions()])

        print(f"Found {len(result.signatures)} barcode signature(s)")
        for barcode in result.signatures:
            print(f"Page {barcode.page_number}: {barcode.encode_type.type_name} barcode '{barcode.text}' "
                  f"at ({barcode.left}, {barcode.top}), size {barcode.width}x{barcode.height}")

if __name__ == "__main__":
    search_barcodes()
signed.pdf is the sample file used in this example. Click here to download it.
Found 2 barcode signature(s)
Page 1: Code128 barcode '123456789012' at (400, 375), size 170x45
Page 1: Code39 barcode 'JS-2026' at (400, 430), size 170x45

Download full output

Advanced Search Options

The BarcodeSearchOptions class provides properties to narrow the search:

  • encode_type returns only barcodes of the given type, for example BarcodeTypes.CODE128;
  • text and match_type return only barcodes whose text matches;
  • all_pages and page_number search a single page instead of the whole document (page numbers start at 1);
  • return_content and return_content_type also return the barcode image.
from groupdocs.signature import Signature
from groupdocs.signature.domain import BarcodeTypes, TextMatchType
from groupdocs.signature.options import BarcodeSearchOptions

def search_barcodes_with_filters():
    with Signature("signed.pdf") as signature:
        options = BarcodeSearchOptions()
        # Search the first page only
        options.all_pages = False
        options.page_number = 1
        # Return only Code 128 barcodes whose text starts with "1234"
        options.encode_type = BarcodeTypes.CODE128
        options.text = "1234"
        options.match_type = TextMatchType.STARTS_WITH

        result = signature.search([options])

        print(f"Found {len(result.signatures)} matching barcode signature(s)")
        for barcode in result.signatures:
            print(f"Page {barcode.page_number}: {barcode.encode_type.type_name} barcode '{barcode.text}'")

if __name__ == "__main__":
    search_barcodes_with_filters()
signed.pdf is the sample file used in this example. Click here to download it.
Found 1 matching barcode signature(s)
Page 1: Code128 barcode '123456789012'

Download full output

Additional Resources

GitHub Examples

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

Free Online Apps

Along with full Python library we provide simple but powerful free Apps.

You are welcome to search for barcode signatures in documents with our free online apps: