Barcode Reader

Constructor
dynamsoft.BarcodeReader()
Methods
decode() decodeBase64String() getRuntimeSettings()
updateRuntimeSettings() resetRuntimeSettings()
dynamsoft.BarcodeReader.initServiceConnection()
Properties
productKey bAutoConnectService
resourcesPath ifCheck64bitServiceFirst
Events
onAutoConnectServiceSuccess onAutoConnectServiceError
Others
Enumerations Errors

Code example

The following code example demonstrates how to use the APIs above to perform barcode reading.

var reader = new dynamsoft.BarcodeReader("<Put your license key here>");
var runtimeSettings = reader.getRuntimeSettings();
runtimeSettings.mBarcodeFormatIds = 1023; // 1D Barcodes
reader.updateRuntimeSettings(runtimeSettings);
var idx = DWObject.GetSelectedImageIndex(0);
var url = DWObject.GetImagePartURL(idx);
reader.decode(url).then(function(results){
    for(var i = 0; i < results.length; ++i){
        console.log(results[i].BarcodeText);
        console.log(results[i].LocalizationResult.ExtendedResultArray[0].Confidence);
    }
});

Constructor

dynamsoft.BarcodeReader()
Creates an instance of BarcodeReader.
Syntax dynamsoft.BarcodeReader();
or
dynamsoft.BarcodeReader(licenceKeys);
Parameters string licenceKeys (optional): The license key for the Barcode Reader add-on.
Return value dynamsoft.BarcodeReader
Example
var reader = new dynamsoft.BarcodeReader();
Usage notes If the parameter licenceKeys is not set, the SDK will get the license key from dynamsoft.dbrEnv.productKey
Availability lo
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.1 ✓ | v14.1

Methods

decode()
Decodes barcodes from an image.
Syntax .decode(source);
Parameters The image to be decoded. It supports png, jpeg, bmp and tiff files.
The parameter source supports the following types:
string source (dcsUrl)
string source (dwtUrl)
Return value Promise(resolve(array TextResult), reject(ex))
Methods available in the TextResult object:
Members Description
ResultType emResultType The barcode format.
pszBarcodeFormatString Barcode type in string.
pszBarcodeText The barcode text, ends by '\0'.
pBarcodeBytes The barcode content in a byte array.
nBarcodeBytesLength The length of the byte array.
SLocalizationResult pLocalizationResult The corresponding localization result.
Example
// dwtUrl: HTML5 Edition only
reader.decode('dwt://dwt_trial_13000404/img?id=306159652&index=0&t=1502184632022').then(
    results=>{
    for(var i = 0; i < results.length; ++i){
        console.log(results[i].BarcodeText);
        // Confidence >= 30 is reliable
        console.log(results[i].LocalizationResult.ExtendedResultArray[0].Confidence);
    }
});
// dcsUrl
reader.decode('dcs://dcs_trial_6110531/img?id=306159652&index=0&t=1502184632022').then(
    function(results){
    // ie6-7 does not support console.log
    var messageArr = [];
    for(var i = 0; i < results.length; ++i){
        messageArr.push(results[i].BarcodeText);
        // Confidence >= 30 is reliable
        messageArr.push(results[i].LocalizationResult.ExtendedResultArray[0].Confidence);
    }
    alert(messageArr.join(''));
})['catch'](function(ex){
    // ie6-9 does not support '.catch(function(ex){...})'
    if(ex){alert(ex.message||ex);}
});
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
decodeBase64String()
Decodes barcodes from a base64 image.
Syntax .decodeBase64String(base64Str);
Parameters string base64Str: The barcode image to be decoded.
Return value Promise(resolve(array TextResult), reject(ex))
Methods available in the TextResult object:
Members Description
ResultType emResultType The barcode format.
pszBarcodeFormatString Barcode type in string.
pszBarcodeText The barcode text, ends by '\0'.
pBarcodeBytes The barcode content in a byte array.
nBarcodeBytesLength The length of the byte array.
SLocalizationResult pLocalizationResult The corresponding localization result.
Example
var base64str = 'data:image/png;base64,xxxxxxx';
//with mime
reader.decodeBase64String(base64str).then(results=>{
    for(var i = 0; i < results.length; ++i){
        console.log(results[i].BarcodeText);
    }
});
//without mime
reader.decodeBase64String(base64str.substring(base64str.indexOf(',') + 1)).then(results=>{
    for(var i = 0; i < results.length; ++i){
        console.log(results[i].BarcodeText);
    }
});
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
getRuntimeSettings()
Gets the current barcode reading settings.
Syntax .getRuntimeSettings();
Parameters None.
Return value PlainObject
Example
var mysettings = reader.getRuntimeSettings();
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
updateRuntimeSettings()
Updates the current barcode reading settings.
Syntax .updateRuntimeSettings(settings);
Parameters PublicRuntimeSettings Object settings: A struct that represents barcode reader settings.
typedef struct PublicRuntimeSettings
{
    number mTimeout;
    number mBarcodeFormatIds;
    number mTextureDetectionSensitivity;
    number mDeblurLevel;
    number mAntiDamageLevel;
    number mMaxBarcodesCount;
    number mScaleDownThreshold;
    number mGrayEqualizationSensitivity;
    number mExpectedBarcodesCount;
};
For more info, please refer to PublicParameterSettings.
Return value undefined
Example
//get the barcode reading settings
var settings = reader.getRuntimeSettings();
//change the settings
settings.mBarcodeFormatIds = 1023; // 1D barcodes
settings.mExpectedBarcodesCount = 10;
settings.mDeblurLevel = 9;
settings.mAntiDamageLevel = 9;
settings.mScaleDownThreshold = 3000;
//update the settings
reader.updateRuntimeSettings(settings);
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
resetRuntimeSettings()
Resets all barcode reading settings to default values.
Syntax .resetRuntimeSettings();
Parameters None.
Return value undefined
Example
reader.resetRuntimeSettings();
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
dynamsoft.BarcodeReader.initServiceConnection()
Initializes the connection to the Dynamsoft Service.
Syntax dynamsoft.BarcodeReader.initServiceConnection();
Parameters None.
Return value Promise(resolve(null), reject(ex))
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1

Properties

productKey
Returns or sets the license key for Barcode Reader add-on.
Type string
Accessors Get Set
Usage notes If you don’t pass a license or the license has expired, the barcode reader add-on will continue to function normally but the last three characters of the barcode result will be masked with “***”.
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
bAutoConnectService
Returns or sets whether to connect to the Dynamsoft Service automatically.
Type boolean
Accessors Get Set
Usage notes The default value of bAutoConnectService is true.
If you want to connect to the service manually, please set it to false before loading "dynamsoft.barcodereader.min.js" and call dynamsoft.BarcodeReader.initServiceConnection when needed.
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
resourcesPath
Returns or sets where the barcode reader related dependencies are placed. This is a relative path to the current web page.
Type string
Accessors Get Set
Usage notes The path is very important as it points to all the JavaScript files, MSI file, images, etc. necessary for the barcode reader add-on to work correctly.
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
ifCheck64bitServiceFirst
Returns or sets whether to use Dynamsoft Service 64-bit first.
Type string
Accessors Get Set
Usage notes The default value of ifCheck64bitServiceFirst is false.
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1

Events

onAutoConnectServiceSuccess
The success callback function of the service connection.
Syntax dynamsoft.dbrEnv.onAutoConnectServiceSuccess = function(){ ... };);
Arguments None.
Example
dynamsoft.dbrEnv.onAutoConnectServiceSuccess = function(){
    console.log("success");
};
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1
onAutoConnectServiceError
The failure callback function of the service connection.
Syntax dynamsoft.dbrEnv.onAutoConnectServiceError = function(status){ ... };
Arguments
  • status: The status of the service.
Example
dynamsoft.dbrEnv.onAutoConnectServiceError = function(status){
    console.log("error");
};
Availability
ActiveXH5(Win)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v14.3.1 ✓ | v14.1

Error

Error dynamsoft.BarcodeReader.BarcodeReaderException

Member Type Description
code number dynamsoft.BarcodeReader.EnumErrorCode The error code.
message String The error string.

Environment APIs (Optional)

The following code example demonstrates how to set the Barcode Reader environment.

// All settings are optional, including dynamsoft and dynamsoft.dbrEnv.
dynamsoft = self.dynamsoft || {};
dynamsoft.dbrEnv = dynamsoft.dbrEnv || {};
dynamsoft.dbrEnv.productKey = "<a license key>",
dynamsoft.dbrEnv.bAutoConnectService = true;
dynamsoft.dbrEnv.resourcesPath = 'DBRResources';
dynamsoft.dbrEnv.ifCheck64bitServiceFirst = true;
dynamsoft.dbrEnv.onAutoConnectServiceSuccess = function(){
    console.log("success");
};
dynamsoft.dbrEnv.onAutoConnectServiceError = function(status){
    console.log("error");
};

Enumerations

enum dynamsoft.BarcodeReader.EnumBarcodeFormat

dynamsoft.BarcodeReader.EnumBarcodeFormat.All = 503317503;
dynamsoft.BarcodeReader.EnumBarcodeFormat.OneD = 0x3FF;
dynamsoft.BarcodeReader.EnumBarcodeFormat.CODE_39 = 0x1;
dynamsoft.BarcodeReader.EnumBarcodeFormat.CODE_128 = 0x2;
dynamsoft.BarcodeReader.EnumBarcodeFormat.CODE_93 = 0x4;
dynamsoft.BarcodeReader.EnumBarcodeFormat.CODABAR = 0x8;
dynamsoft.BarcodeReader.EnumBarcodeFormat.ITF = 0x10;
dynamsoft.BarcodeReader.EnumBarcodeFormat.EAN_13 = 0x20;
dynamsoft.BarcodeReader.EnumBarcodeFormat.EAN_8 = 0x40;
dynamsoft.BarcodeReader.EnumBarcodeFormat.UPC_A = 0x80;
dynamsoft.BarcodeReader.EnumBarcodeFormat.UPC_E = 0x100;
dynamsoft.BarcodeReader.EnumBarcodeFormat.INDUSTRIAL_25 = 0x200;
dynamsoft.BarcodeReader.EnumBarcodeFormat.PDF417 = 0x2000000;
dynamsoft.BarcodeReader.EnumBarcodeFormat.QR_CODE = 0x4000000;
dynamsoft.BarcodeReader.EnumBarcodeFormat.DATAMATRIX = 0x8000000;
dynamsoft.BarcodeReader.EnumBarcodeFormat.AZTEC = 0x10000000;

enum dynamsoft.BarcodeReader.EnumErrorCode

dynamsoft.BarcodeReader.EnumErrorCode.DBR_SYSTEM_EXCEPTION = 1;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_SUCCESS = 0;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_UNKNOWN = -10000;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_NO_MEMORY = -10001;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_NULL_REFERENCE = -10002;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_LICENSE_INVALID = -10003;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_LICENSE_EXPIRED = -10004;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_FILE_NOT_FOUND = -10005;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_FILETYPE_NOT_SUPPORTED = -10006;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_BPP_NOT_SUPPORTED = -10007;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_INDEX_INVALID = -10008;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_BARCODE_FORMAT_INVALID = -10009;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_CUSTOM_REGION_INVALID = -10010;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_MAX_BARCODE_NUMBER_INVALID = -10011;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_IMAGE_READ_FAILED = -10012;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_TIFF_READ_FAILED = -10013;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_QR_LICENSE_INVALID = -10016;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_1D_LICENSE_INVALID = -10017;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_DIB_BUFFER_INVALID = -10018;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_PDF417_LICENSE_INVALID = 10019;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_DATAMATRIX_LICENSE_INVALID = -10020;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_PDF_READ_FAILED = -10021;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_PDF_DLL_MISSING = -10022;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_PAGE_NUMBER_INVALID = -10023;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_CUSTOM_SIZE_INVALID = -10024;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_CUSTOM_MODULESIZE_INVALID = -10025;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_RECOGNITION_TIMEOUT = -10026;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_PARSE_FAILED = -10030;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_TYPE_INVALID = -10031;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_KEY_INVALID = -10032;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_VALUE_INVALID = -10033;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_NAME_KEY_MISSING = -10034;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_NAME_VALUE_DUPLICATED = -10035;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_TEMPLATE_NAME_INVALID = -10036;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_JSON_NAME_REFERENCE_INVALID = -10037;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_PARAMETER_VALUE_INVALID = 10038;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_DOMAIN_NOT_MATCHED = -10039;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_RESERVEDINFO_NOT_MATCHED = -10040;
dynamsoft.BarcodeReader.EnumErrorCode.DBR_DBRERR_AZTEC_LICENSE_INVALID = -10041;

results matching ""

    No results matching ""

    results matching ""

      No results matching ""