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 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 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 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;
}
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.
Barcode Document Formats
AAMVA
- Identifies an AAMVA Driver LicenseBOARDING_PASS
- Identifies a Boarding PassDE_MEDICAL_PLAN
- Identifies a German Medical Plan CodeMEDICAL_CERTIFICATE
- Identifies a Medical Certificate CodeID_CARD_PDF_417
- Identifies a PDF417 code (eg. ID card, passport, driver license)SEPA
- Identifies a SEPA QR CodeSWISS_QR
- Identifies a Swiss QR CodeVCARD
- Identifies a VCARD QR CodeGS1
- Identifies a GS1 Code
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.