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:
Create a new instance of the Signature class and pass the source document path as a parameter.
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.
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportBarcodeTypes,TextMatchTypefromgroupdocs.signature.optionsimportBarcodeSearchOptionsdefsearch_barcodes_with_filters():withSignature("signed.pdf")assignature:options=BarcodeSearchOptions()# Search the first page onlyoptions.all_pages=Falseoptions.page_number=1# Return only Code 128 barcodes whose text starts with "1234"options.encode_type=BarcodeTypes.CODE128options.text="1234"options.match_type=TextMatchType.STARTS_WITHresult=signature.search([options])print(f"Found {len(result.signatures)} matching barcode signature(s)")forbarcodeinresult.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'