Barcode Xpress for Node.js v13.9 - Updated
module barcode-js
API Reference > module barcode-js

Module: barcode-js

Members

(static) module.exports.BarcodeType :string

Enum of barcode types
Type:
  • string
Properties:
Name Type Description
ADD2 string Indicates an Add 2 barcode type.
ADD5 string Indicates an Add 5 barcode type.
AUSTRALIANPOST4STATE string Australian Post 4 State barcode.
AZTEC string Aztec barcode.
BCDMATRIX string Indicates a BCD Matrix barcode type.
CODABAR string Indicates a Codabar barcode type.
CODE32 string Indicates a Code 32 barcode type.
CODE39 string Indicates a Code 39 barcode type.
CODE39EXT string Indicates a Code 39 Extended barcode type.
CODE93 string Indicates a Code 93 barcode type.
CODE93EXT string Indicates a Code 93 Extended barcode type.
CODE128 string Indicates a Code 128 barcode type.
DATALOGIC2OF5 string Indicates a DataLogic 2 of 5 barcode type.
DATAMATRIX string Indicates a DataMatrix barcode type.
EAN8 string Indicates an EAN-8 barcode type.
EAN13 string Indicates an EAN-13 barcode. This also supports a JAN barcode which is an EAN-13 with country code 49.
EAN128 string Indicates an EAN-128 barcode type.
GS1DATABAR string GS1 DataBar barcode
IATA2OF5 string Indicates an IATA 2 of 5 barcode type.
INDUSTRIAL2OF5 string Indicates an Industry 2 of 5 barcode type.
INTELLIGENTMAIL string United States Postal IntelligentMail 4 State barcode.
INTERLEAVED2OF5 string Indicates an Interleaved 2 of 5 barcode type.
INVERTED2OF5 string Indicates an Inverted 2 of 5 barcode type.
MATRIX2OF5 string Indicates a Matrix 2 of 5 barcode type.
MICROPDF417 string MicroPDF417 barcode
MICROQRCODE string Indicates a Micro QR barcode type.
PATCHCODE string Indicates a Patch Code.
PDF417 string Indicates a PDF417 barcode type.
PLANET string Indicates a PLANET barcode type.
POSTNET string Indicates a PostNet barcode type.
QRCODE string QR Code barcode
ROYALPOST4STATE string Royal Post 4 State barcode
UPCA string Indicates a UPC-A barcode type.
UPCE string Indicates a UPC-E barcode type.
UPU4STATE string UPU 4-State barcode
ALL string Indicates All barcode types.
ALL_1D string Indicates All 1D barcode types.
ALL_2D string Indicates All 2D barcode types.

(static) module.exports.ModeTransitionType :number

Enum of possible state transition types in the barcode reader's internal state. Many barcode types are encoded as a state machine. When reading the data encoded therein, the machine will often move from one state to another. This information give decoders more information as to the inner context of the barcode's information.
Type:
  • number
Properties:
Name Type Description
QR_None number No mode transition has occurred
QR_Numeric number QR Code's Numeric mode
QR_Alpha number QR Code's Alphanumeric mode
QR_Byte number QR Code's Byte mode
QR_Kanji number QR Code's Kanji mode
QR_ECI number QR Code's Extended Channel Interpretation mode
QR_FNC1First number QR Code's FNC1 mode, first position
QR_FNC1Second number QR Code's FNC1 mode, second position
QR_StructuredAppend number QR Code's Structured Append mode

Methods

(static) module.exports.analyze(input, paramsopt, callbackopt) → {Promise|undefined}

Detects barcodes on the given bitmap image.
Parameters:
Name Type Attributes Description
input string | Buffer | stream.Readable | jimp.image | object | Promise Input image to be anaylzed.
The input can be one of the following types:
  • string - A path to a file or URL.
  • Buffer - A buffer containing image bytes from a supported image format.
  • stream.Readable - A readable stream. Image data will be read entirely into a Buffer before processing.
  • jimp.image - A jimp image.
  • object - An object with a required url member and optional http.request options (jimp style).

  • or a Promise that returns one of the above types.
params object <optional>
Parameters used by the analyze method.
callback function <optional>
Use callback function, if defined, otherwise return a Promise.
Returns:
Returns a Promise if callback is not a function.
The Promise will return an array of result.
Type
Promise | undefined
Examples

Call using async/await

const bx = require('barcode-js');

const analyzeBarcodes = async (input, params) => {
    try {
      const results = await bx.analyze(input, params);
      console.log('Results:' + JSON.stringify(results));
  }
  catch(err) {
      console.error(`Fatal: Error analyzing image input\n${err}`);
  }
};

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};

// Call analyze.
analyzeBarcodes(filePath, params);

Call using promises

const bx = require('barcode-js');

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};

// Call analyze.
bx.analyze(filePath, params)
   .then(results => {
       console.log('Results:' + JSON.stringify(results));
  })
  .catch(error => {
      console.log('Error:' + JSON.stringify(error));
  });

Call using callback function

const bx = require('barcode-js');

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};

// Call analyze.
bx.analyze(filePath, params, function (err, results) {
   if (err) {
       console.error(`Fatal: Error analyzing image input\n${err}`);
       return;
   }
   console.log('Callback Results: ' + JSON.stringify(results));
}); 

Call with a jimp.image

const bx = require('barcode-js');
const jimp = require('jimp');

const analyzeBarcodes = async (filePath, params) => {
    try {
      const image = await jimp.read(filePath);
      const results = await bx.analyze(image, params);
      console.log('Results:' + JSON.stringify(results));
  }
  catch(err) {
      console.error(`Fatal: Error analyzing image input\n${err}`);
  }
};

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};

analyzeBarcodes(filePath, params);

 

Call with promise that returns a jimp.image

const bx = require('barcode-js');
const jimp = require('jimp');

const analyzeBarcodes = async (inputPromise, params) => {
    try {
      const results = await bx.analyze(inputPromise, params);
      console.log('Results:' + JSON.stringify(results));
  }
  catch(err) {
      console.error(`Fatal: Error analyzing image input\n${err}`);
  }
};

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};
const imagePromise = jimp.read(filePath);

analyzeBarcodes(imagePromise, params);

Call with image in a buffer

const bx = require('barcode-js');
const fs = require('fs');

const analyzeBarcodes = async (input, params) => {
    try {
      const results = await bx.analyze(input, params);
      console.log('Results:' + JSON.stringify(results));
  }
  catch(err) {
      console.error(`Fatal: Error analyzing image input\n${err}`);
  }
};

// Set up parameters.
const filePath = 'test.bmp';
const params = {type: bx.BarcodeType.ALL};
const imageBuffer = fs.readFileSync(filePath);

analyzeBarcodes(imageBuffer, params);

(static) module.exports.setOemLicenseKey(OEMLicenseKey)

Sets the BarcodeXpress runtime OEM license key.

Remarks

When OEM runtime licenses are purchased, the OEM license key is provided in the purchase confirmation email.
Parameters:
Name Type Description
OEMLicenseKey string The OEM license key required for OEM licensing.
Example

Set OEM License Key

const  bx = require('barcode-js');
bx.setOemLicenseKey('1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation...');

(static) module.exports.setSolutionKey(v1, v2, v3, v4)

Sets the BarcodeXpress control runtime license deployment key.

Remarks

This is the solution key required for all runtime licensing. The four integers are provided at the time of purchase of the runtime licenses along with the solution name, which is set with the setSolutionName method.
Parameters:
Name Type Description
v1 number Unlock key 1
v2 number Unlock key 2
v3 number Unlock key 3
v4 number Unlock key 4
Example

Set Solution Key

const bx = require('barcode-js');
bx.setSolutionKey(12345, 12345, 12345, 12345);

(static) module.exports.setSolutionName(solutionName)

Sets the BarcodeXpress control runtime license deployment solution name.

Remarks

This is the name of the runtime license solution. The solution name is provided in the purchase confirmation email when runtime licenses are purchased.
Parameters:
Name Type Description
solutionName string The solution name.
Example

Set Solution Name

const bx = require('barcode-js');
bx.setSolutionName('YourSolutionName');

Type Definitions

analyzeCallback(error, results)

Optional Callback function used by analyze.
Parameters:
Name Type Description
error object undefined if no error is encounted.
results object Array of result, or undefined if an error was encountered.

ModeTransition

When reading a barcode, many symbologies will go through state changes that may give extra context as to the content types inside the barcode (eg. Kanji). This member was added to give the user extra information about the inner workings of the barcode's state. Note: Currently only enabled with QR Codes.
Type:
  • object
Properties:
Name Type Description
ModeTransition.index number The index in the result value where the mode transition occurs.
ModeTransition.type number The transition type. See ModeTransitionType for a list of allowed types.

params

Input parameters used by the analyze method.
Type:
  • object
Properties:
Name Type Attributes Default Description
params.type string | array <optional>
BarcodeType.ALL_1D A single string with the barcode type to find or an array of strings with the barcode types to find.
See BarcodeType for a list of allowed types.
Default: Find all 1D barcode types.
params.area object <optional>
{x:0,y:0:width:0,height:0} The rectangluar area of the image, in pixels, to search for barcodes.
Default: Entire image.
parameters.additionalReadingPass boolean <optional>
false Specifies whether an additional processing pass will be performed on a scaled (reduced) version of the original image (scale factor equal to 0.5). After analyzing both these images, results from the pass that yields a higher confidence value would be reported. This step is strictly an extra analysis step which increases response time. It can be used for barcode images with repetitive noise artifacts around the bars which cause normal recognition pass to misread.
Default: No additional reading pass.
params.code39StartStopPatternsAreMandatory boolean <optional>
true Specifies whether or not Barcode Xpress will find and decode Code 39 / Code 39 Extended barcodes when their start and stop patterns are missing. If set to true, only regular (barcode has both start and stop patterns) barcodes are recognized. This is relevant for Code39 and Code39 Extended barcode symbologies.
Default: Decode only barcodes with start and stop patterns.
params.royalMailVariableLengthDecoding boolean <optional>
false Specifies whether or not to decode Royal Mail barcodes of any length. If set to false, only Royal Mail barcodes matching the lengths in the RM4SCC specification will be decoded.
Default: No variable length decoding.
Examples

Setting barcode type as a single string.

const bx = require('barcode-js');
const params = {
  type : bx.BarcodeType.DATAMATRIX
}

Setting barcode type as an array of string.

const bx = require('barcode-js');
const params = {
  type : [bx.BarcodeType.CODE128, bx.BarcodeType.PDF417]
}

Limiting search area in the image.

const bx = require('barcode-js');
const params = {
  area : { x: 10, y: 10, width: 200, height: 100}
}

All barcode types and search entire image.

const bx = require('barcode-js');
const params = {
  type : bx.BarcodeType.ALL,
  area : { x: 0, y: 0, width: 0, height: 0}
}

point

A 2D point,in pixels, within an image.
Type:
  • object
Properties:
Name Type Description
x number The x coordinate of the point
y number The y cooridnate of the point

rectangle

A rectangular area, in pixels, within the image.
Type:
  • object
Properties:
Name Type Description
rectangle.x number The x coordinate of the area
rectangle.y number The y coordinate of the area
rectangle.width number The width of area
rectangle.height number The height of area

result

The result object contains information about a found barcode.

Remarks

The analyze method produces an array of result objects. Each element of the results array contains the information of a single recognized barcode. Since BarcodeXpress can return multiple barcode results from a single scan, the detected barcode results are sorted using the following criteria.
  • The confidence factor is used to sort the barcode results from the highest confidence to the lowest confidence.
  • For any barcodes with the same confidence value, they are sorted by their location, from top to bottom, then left to right.
  • Note: All solved barcodes are ordered before unsolved barcodes.
Type:
  • object
Properties:
Name Type Description
area area The bounding rectangle of the recognized barcode.
checksumLength number The number of characters in the recognized checksum.
checksumValid boolean Indicates whether the checksum for a recognized barcode is valid.
confidence number The confidence of the recognized barcode.
corners array Array of points These are the four corners of the found barcode.
info2d ResultInfo2d The ResultInfo2d information for the barcode.
modeTransitions ModeTransition Array of ModeTransitions the reader goes through while decoding the barcode.
name string The name of the recognized barcode.
skew number The angle of skew for the recognized barcode analyzed.
type string The type of the recognized barcode.
value string The text value of the recognized barcode.
valueRaw Buffer The raw value of the recognized barcode.
Example

Log results to console.

function logResults(results) {
   results.forEach(function (result) {
       console.log('Result: ');
       console.log('\n\t type: ' + result.type);
       console.log('\n\t value: ' + result.value);
       console.log('\n\t confidence: ' +  result.confidence);
       console.log('\n\t area: ' +  JSON.stringify(result.area));
       console.log('\n\t corners: ' +  JSON.stringify(result.corners));
       console.log('\n');
   });
}

ResultInfo2d

This object contains 2D information for certain barcode types. It is currently only supported for PDF417 barcode types. Fields will be 0 for unsupported barcode types, or if the reader is otherwise unable to determine the value.
Type:
  • object
Properties:
Name Type Description
ResultInfo2d.columns number Specifies the number of columns in the barcode as defined by the indicator pattern.
ResultInfo2d.columnsDetected number Specifies the number of columns detected in the barcode image.
ResultInfo2d.errorCorrectionLevel number Specifies the amount of error correction detected for barcodes that support it.
ResultInfo2d.rows number Specifies the number of rows in the barcode as defined by the indicator pattern.
ResultInfo2d.rowsDetected number Specifies the number of rows detected in the barcode image.

Is this page helpful?
Yes No
Thanks for your feedback.