Skip to main content

Scanning a barcode from an image | Capacitor Document Scanner

ScanbotSDK.detectBarcodesOnImage(args: DetectBarcodesOnImageArguments) ScanbotSDK.detectBarcodesOnImages(args: DetectBarcodesOnImagesArguments)

Detects barcodes on a still image (PNG or JPG file) regardless of the image source (e.g. scanned document image, image picked from photo library, etc).

Example for detecting barcodes on the Image

import ScanbotSDK from 'capacitor-plugin-scanbot-sdk';

// Always make sure you have a valid license on runtime via ScanbotSDK.getLicenseInfo()
if (!licenseCheckMethod()) { return; }

Detection on a Single Image

const result = await ScanbotSDK.detectBarcodesOnImage({
imageFileUri: 'file:///some/image-file.jpg',
//barcodeFormats: ['QR_CODE', 'EAN_13', ...], // optional filter for specific barcode types
// see further args...
});

// handle the detected barcode(s) from result
// result.barcodes[n]...

Input Args

interface DetectBarcodesOnImageArguments {
/**
* The input image file URI.
*/
imageFileUri: string;
/**
* Accepted barcode formats
*/
barcodeFormats?: BarcodeFormat[];
/**
* An optional array of barcode document formats that act as a detection filter.
* By default all supported document formats will be detected.
*/
acceptedDocumentFormats?: BarcodeDocumentFormat[];
/**
* Optional minimum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF barcodes only.
*/
minimumTextLength?: number;
/**
* Optional maximum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF barcodes only.
*/
maximumTextLength?: number;
/**
* Optional minimum required quiet zone on the barcode.
* Measured in modules (the size of minimal bar on the barcode).
* The default is 10.
* NOTE: This feature works on ITF barcodes only.
*/
minimum1DBarcodesQuietZone?: number;
/**
* With this option enabled, the scanner removes checks digits for UPC, EAN and MSI Plessey codes.
* Has no effect if both single and double digit MSI Plessey checksums are enabled.
* The default is `false`
*/
stripCheckDigits?: boolean;
/**
* The GS1 handling mode. The default value is PARSE.
*/
gs1HandlingMode?: Gs1HandlingMode;
/**
* The checksum algorithm for MSI Plessey barcodes.
* The default value is Mod10.
*/
msiPlesseyChecksumAlgorithm?: MSIPlesseyChecksumAlgorithm;
}

Detection on Multiple Images

const result = await ScanbotSDK.detectBarcodesOnImages({
imageFileUris: ['file:///some/image-file_1.jpg', 'file:///some/image-file_2.jpg'],
//barcodeFormats: ['QR_CODE', 'EAN_13', ...], // optional filter for specific barcode types
// see further args...
});

// handle the detected barcode(s) from result
// result.barcodes[n]...

Input Args

interface DetectBarcodesOnImagesArguments {
/**
* The input image files URIs
*/
imageFileUris: string[];
/**
* Accepted barcode formats
*/
barcodeFormats?: BarcodeFormat[];
/**
* An optional array of barcode document formats that act as a detection filter.
* By default all supported document formats will be detected.
*/
acceptedDocumentFormats?: BarcodeDocumentFormat[];
/**
* Optional minimum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF barcodes only.
*/
minimumTextLength?: number;
/**
* Optional maximum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF barcodes only.
*/
maximumTextLength?: number;
/**
* Optional minimum required quiet zone on the barcode.
* Measured in modules (the size of minimal bar on the barcode).
* The default is 10.
* NOTE: This feature works on ITF barcodes only.
*/
minimum1DBarcodesQuietZone?: number;
/**
* With this option enabled, the scanner removes checks digits for UPC, EAN and MSI Plessey codes.
* Has no effect if both single and double digit MSI Plessey checksums are enabled.
* The default is `false`
*/
stripCheckDigits?: boolean;
/**
* When set to `true`, the scanner assumes that the barcode can be a GS1 barcode.
* Turn it off, if you don't want to see decoded FNC1 characters ("]C1" and ASCII char 29).
* The default value is `true`.
* NOTE: Currently works for CODE128 barcodes only!
*/
gs1DecodingEnabled?: boolean;
/**
* The checksum algorithm for MSI Plessey barcodes.
* The default value is Mod10.
*/
msiPlesseyChecksumAlgorithm?: MSIPlesseyChecksumAlgorithm;
}

Handling the Result

The result object contains the following fields:

  • result.status: Result status, 'OK' if at least one barcode was scanned, 'CANCELED' if the user canceled the operation.
  • result.barcodes[]: An array of detected barcodes. If no barcodes were detected, the array will be empty or null.
  • result.barcodes[n].type: Format of detected barcode/QR code (e.g. CODE_128, EAN_13, QR_CODE, etc).
  • result.barcodes[n].text: Text value of detected and decoded barcode/QR code.
  • result.canceledDueToTimeout: Optional boolean field. Available only in case of status="CANCELED":
    • true If the config value autoCancelTimeout was specified, AND the UI was auto-canceled due to timeout.
    • false If the user closed the UI via the "cancel" button.

Barcode Document Formats

  • AAMVA - American Association of Motor Vehicle Administrators barcode document
  • BOARDING_PASS - Boarding pass barcode document
  • DE_MEDICAL_PLAN - German medical plan barcode document
  • MEDICAL_CERTIFICATE - German medical certificate barcode document
  • ID_CARD_PDF_417 - ID Card barcode document
  • SEPA - SEPA barcode document
  • SWISS_QR - Swiss QR barcode document
  • VCARD - VCard barcode document
  • GS1 - GS1 barcode document

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?