Dev Center
Table of contents

BarcodeReader

  • class BarcodeReader

    The BarcodeReader class is used for decoding barcodes from images.

    let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
    let results = await reader.decode(imageSource);
    for(let result of results){
      console.log(result.barcodeText);
    }
    

Index

Initialize the Engine

Static Property Description
engineResourcePath Specifies the WASM engine URL.
_bUseFullFeature If set to true, uses the full WASM engine.
Static Method Description
isLoaded Checks if the decoding module is loaded.
loadWasm Manually loads and compiles the decoding WASM module.


Create and Destroy Instance

Property Description
bDestroyed Indicates whether the instance has been destroyed.
Static Method Description
createInstance Creates a BarcodeReader instance.
Method Description
destroy Destroies the BarcodeReader instance.


Decode Barcodes

Method Description
decode Decodes barcodes from images, binary data, URLs, and more.
decodeBase64String Decodes barcodes from a base64 encoded string.
decodeUrl Decodes barcodes from a URL.
decodeBuffer Decodes barcodes from raw image data.


Decoding Settings

Method Description
getRuntimeSettings Gets current runtime settings.
updateRuntimeSettings Modifies and updates the current runtime settings.
resetRuntimeSettings Resets runtime settings to default.
getModeArgument Gets argument value for the specified mode parameter.
setModeArgument Sets argument value for the specified mode parameter.


License

Property Description
productKeys Gets or sets the Dynamsoft Barcode Reader SDK product keys.
licenseServer Specifies the license server URL.
handshakeCode Uses Handshake Code to get authentication.
organizationID Uses Organization ID to get authentication.
sessionPassword Specifies a password to protect the Handshake Code from abuse.


Others

Static Property Description
version Gets the current product version.
Property Description
bSaveOriCanvas If set to true, saves the original image in oriCanvas .
oriCanvas An canvas object that holds the original image.
Static Method Description
detectEnvironment Detects environments and gets a report.

Initialize the Engine

engineResourcePath

  • static engineResourcePath: string

    Manually specifies the URL of Barcode Reader SDK engine (WASM) . The property needs to be set before loadWasm.

    Dynamsoft.DBR.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.2.5/dist/";
    await Dynamsoft.DBR.BarcodeReader.loadWasm();
    


_bUseFullFeature

  • static _bUseFullFeature: boolean = false

    Whether to use full WASM engine. The property needs to be set before loadWasm. The default is ‘false’.

     DBR.BarcodeReader._bUseFullFeature = true;
     await DBR.BarcodeReader.loadWasm();
    

    Learn more about differences between compact and full WASM engines.


isLoaded

  • static isLoaded(): boolean

    Checks if the decoding module is loaded.


loadWasm

  • static loadWasm(): Promise<void>

    Before most operations, loadWasm needs to be excuted firstly.

    Most time, you do not need excute loadWasm manually. Because when you excute createInstance, loadWasm will be excuted implicitly.

    Some properties can’t be changed after loadWasm.

    Calling loadWasm in advance can avoid the long wait when createInstance.

    window.addEventListener('DOMContentLoaded', (event) => {
       DBR.BarcodeReader.loadWasm();
     });
    


Create and Destroy Instance

bDestroyed

  • bDestroyed: boolean

    Indicates whether the instance has been destroyed.


createInstance

  • static createInstance(): Promise<BarcodeReader>

    Create a BarcodeReader instance.

     let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
    


destroy

  • destroy(): Promise<void>

    Destroies the BarcodeReader instance. If your page needs to create new instances from time to time, don’t forget to destroy unused old instances to avoid possible memory leaks.


Decode Barcode

decode

  • decode (source: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray

    | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement

    | string): Promise<TextResult[]>

    Decodes barcodes from an image.

    The main decoding method can accept a variety of data types, including binary data, images, base64 (with MIME), URL, etc.

    The image format can be png, jpeg, bmp, gif and a few others (some browsers support webp, tif).

    let results = await reader.decode(blob);
    for(let result of results){
        console.log(result.barcodeText);
    }
    
    let results2 = await reader.decode(htmlImageElement);
    let results2 = await reader.decode(url);
     
    // like `data:image/png;base64,iV************`
    let results3 = await reader.decode(strBase64WithMime);
    

    And you can get a frame from the HTMLVideoElement for barcode scanning.

    // The frame currently played will be decoded.
    let results;
    try{
      results = await reader.decode(htmlVideoElement);
    }catch(ex){
      // If no frame in the video, throws an exception.   
    }
    

    If you need to continuously decode a video, you can use BarcodeScanner instead.

    @see decodeBase64String, decodeUrl


decodeBase64String

  • decodeBase64String(base64: string): Promise<TextResult[]>

    The decoding method can accept base64 with or without MIME. e.g. data:image/jpg;base64,Xfjshekk.... or Xfjshekk....

    let results = await reader.decodeBase64String(strBase64);
    for(let result of results){
      console.log(result.barcodeText);
    }
    


decodeUrl

  • decodeUrl(url: string): Promise<TextResult[]>

    The decoding method can accept an URL. The URL source needs to be in the same domain or allowed Cross-Origin Resource Sharing (CORS).

    let results = await reader.decodeUrl("./1.png");
    for(let result of results){
        console.log(result.barcodeText);
    }
    


decodeBuffer


Decoding Settings

getRuntimeSettings

  • getRuntimeSettings(): Promise<RuntimeSettings>

    Gets current runtime settings.

    let settings = await reader.getRuntimeSettings();
    settings.deblurLevel = 5;
    await reader.updateRuntimeSettings(settings);
    


updateRuntimeSettings

  • updateRuntimeSettings(settings: RuntimeSettings | string): Promise<void>

    Updates runtime settings with a given struct or a string of speed, balance or coverage to use preset settings for BarcodeReader.

    The default runtime setting for BarcodeReader is coverage.

    await reader.updateRuntimeSettings('balance');
    let settings = await reader.getRuntimeSettings();
    settings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_ONED;
    await reader.updateRuntimeSettings(settings);
    


resetRuntimeSettings

  • resetRuntimeSettings(): Promise<void>

    Resets all parameters to default values.

    await reader.resetRuntimeSettings();
    


getModeArgument

  • getModeArgument(modeName: string, index: number, argumentName: string): Promise<string>

    Gets argument value for the specified mode parameter.

    let argumentValue = await reader.getModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy");
    

    @see C++ getModeArgument


setModeArgument

  • setModeArgument(modeName: string, index: number, argumentName: string, argumentValue: string): Promise<string>

    Sets argument value for the specified mode parameter.

    await reader.setModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy", "1");
    

    @see C++ setModeArgument


License

productKeys

  • static productKeys: string

    Gets or sets the Dynamsoft Barcode Reader SDK product keys.

    Dynamsoft.DBR.BarcodeReader.productKeys = "PRODUCT-KEYS";
    

    For convenience, you can set productKeys in script tag instead.

    <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.2.5/dist/dbr.js" data-productKeys="PRODUCT-KEYS"></script>
    


licenseServer

  • static licenseServer: string[] | string

    Specifies the license server URL.


handshakeCode

  • static handshakeCode: string

    Gets or sets the Dynamsoft Barcode Reader SDK handshake code. The handshakeCode is an alias of productKeys. Specifically refers to the key that requires network authentication.

    Dynamsoft.DBR.BarcodeReader.handshakeCode = "123****-mytest";
    

    For convenience, you can set handshakeCode in script tag instead.

    <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.2.5/dist/dbr.js" data-handshakeCode="123****-mytest"></script>
    


organizationID

  • static organizationID: string

    Use organization ID to get authentication from network. Keep handshakeCode empty if you want to use default handshake of the organization.

    Dynamsoft.DBR.BarcodeReader.organizationID = "123****";
    

    For convenience, you can set organizationID in script tag instead.

    <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.2.5/dist/dbr.js" data-organizationID="123****"></script>
    


sessionPassword

  • static sessionPassword: string

    Specifies a password to protect the Handshake Code.

    Dynamsoft.DBR.BarcodeReader.handshakeCode = "123****-mytest";
    Dynamsoft.DBR.BarcodeReader.sessionPassword = "@#$%****";
    

    For convenience, you can set organizationID in script tag instead.

    <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.2.5/dist/dbr.js" data-handshakeCode="123****-mytest" data-sessionPassword="@#$%****"></script>
    


Other

bSaveOriCanvas

  • bSaveOriCanvas: boolean = false;

    Whether to save the original image into canvas.

    reader.bSaveOriCanvas = true;
    let results = await reader.decode(source);
    document.body.append(reader.oriCanvas);
    


oriCanvas

  • readonly oriCanvas: HTMLCanvasElement | OffscreenCanvas

    A canvas object that holds the original image.

    reader.bSaveOriCanvas = true;
    let results = await reader.decode(source);
    document.body.append(reader.oriCanvas);
    


version

  • readonly static version: string

    Gets the current product version. Needs to call after loadWasm.

    console.log(Dynamsoft.DBR.BarcodeReader.version); // "loading...(JS 8.2.5.20210426)"
    await Dynamsoft.DBR.BarcodeReader.loadWasm();
    console.log(Dynamsoft.DBR.BarcodeReader.version); // "8.4.0.8960(JS 8.2.5.20210426)"
    


detectEnvironment

  • static detectEnvironment(): Promise<any>

    Detects environments and gets a report.

    console.log(Dynamsoft.DBR.BarcodeReader.detectEnvironment());
    // {"wasm":true, "worker":true, "getUserMedia":true, "camera":true, "browser":"Chrome", "version":90, "OS":"Windows"}
    


This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

version 8.2.5

  • Latest version(10.2.10)
  • Version 10.x
    • Version 10.0.21
    • Version 10.0.20
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.33
    • Version 9.6.32
    • Version 9.6.31
    • Version 9.6.30
    • Version 9.6.21
    • Version 9.6.20
    • Version 9.6.11
    • Version 9.6.10
    • Version 9.6.2
    • Version 9.6.1
    • Version 9.6.0
    • Version 9.3.1
    • Version 9.3.0
    • Version 9.2.13
    • Version 9.2.12
    • Version 9.2.11
    • Version 9.0.2
    • Version 9.0.1
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.7
    • Version 8.8.5
    • Version 8.8.3
    • Version 8.8.0
    • Version 8.6.3
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.5
    • Version 8.2.3
    • Version 8.2.1
    • Version 8.2.0
    • Version 8.1.3
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +