Skip to main content

Scanning a barcode from an image | Cordova Document Scanner

ScanbotSdk.detectBarcodesOnImage(args: DetectBarcodesOnImageArgs) ScanbotSdk.detectBarcodesOnImages(args: DetectBarcodesOnImagesArgs)

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 'cordova-plugin-scanbot-sdk';

private SDK = ScanbotSdk.promisify();

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

Detection on a Single Image

const result = await this.SDK.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 DetectBarcodesOnImageArgs {
/**
* The input image file URI.
*/
imageFileUri: string;
/**
* Accepted barcode formats.
*/
barcodeFormats?: BarcodeFormat[];
/**
* An optional array of barcode document formats that acts as a detection filter.
* By default all supported document formats will be detected.
*/
acceptedDocumentFormats?: BarcodeDocumentFormat[];
/**
* Use a filter to determine which type of barcode can be detected; see `BarcodeFilter`
*/
barcodeFilter?: BarcodeFilter;
/**
* If `true`, enables the mode which slightly decreases the scanning quality and the energy consumption, thus increasing the scanning speed.
* The default is `false`.
* Android only.
*/
lowPowerMode?: boolean;
/**
* Optional minimum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF and MSI Plessey 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 and MSI Plessey barcodes only.
*/
maximumTextLength?: number;
/**
* Optional minimum required quiet zone on the barcode.
* Measured in modules (the size of narrowest bar in the barcode).
* The default is 10.
* NOTE: This feature works on ITF and MSI Plessey barcodes only.
*/
minimum1DBarcodesQuietZone?: number;
/**
* With this option enabled, the scanner removes check 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 [MSIPlesseyChecksumAlgorithm.Mod10].
*/
msiPlesseyChecksumAlgorithm?: MSIPlesseyChecksumAlgorithm;
/*
* The expected density of QR codes. A higher density finds more QR codes in an image but the performance is slightly reduced.
*/
codeDensity?: CodeDensity;
}

Detection on Multiple Images

const result = await this.SDK.detectBarcodesOnImages({
imageFileUri: ['file:///some/image-file.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 DetectBarcodesOnImagesArgs {
/**
* The list of input image files URIs.
*/
imageFilesUris: string[];
/**
* Accepted barcode formats.
*/
barcodeFormats?: BarcodeFormat[];
/**
* An optional array of barcode document formats that acts as a detection filter.
* By default all supported document formats will be detected.
*/
acceptedDocumentFormats?: BarcodeDocumentFormat[];
/**
* Use a filter to determine which type of barcode can be detected; see `BarcodeFilter`
*/
barcodeFilter?: BarcodeFilter;
/**
* If `true`, enables the mode which slightly decreases the scanning quality and the energy consumption, thus increasing the scanning speed.
* The default is `false`.
* Android only.
*/
lowPowerMode?: boolean;
/**
* Optional minimum required text length of the detected barcode.
* The default is 0 (setting is turned off).
* NOTE: This feature works on ITF and MSI Plessey 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 and MSI Plessey barcodes only.
*/
maximumTextLength?: number;
/**
* Optional minimum required quiet zone on the barcode.
* Measured in modules (the size of narrowest bar in the barcode).
* The default is 10.
* NOTE: This feature works on ITF and MSI Plessey barcodes only.
*/
minimum1DBarcodesQuietZone?: number;
/**
* With this option enabled, the scanner removes check 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 [MSIPlesseyChecksumAlgorithm.Mod10].
*/
msiPlesseyChecksumAlgorithm?: MSIPlesseyChecksumAlgorithm;
/*
* The expected density of QR codes. A higher density finds more QR codes in an image but the performance is slightly reduced.
*/
codeDensity?: CodeDensity;
}

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 - Identifies an AAMVA Driver License
  • BOARDING_PASS - Identifies a Boarding Pass
  • DE_MEDICAL_PLAN - Identifies a German Medical Plan Code
  • MEDICAL_CERTIFICATE - Identifies a Medical Certificate Code
  • ID_CARD_PDF_417 - Identifies a PDF417 code (eg. ID card, passport, driver license)
  • SEPA - Identifies a SEPA QR Code
  • SWISS_QR - Identifies a Swiss QR Code
  • VCARD - Identifies a VCARD QR Code

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?