Skip to content

Methods Reference

metafloor edited this page Apr 28, 2021 · 10 revisions

bwipjs.request()

Usage

bwipjs.request(req, res [, overrides])

Returns a PNG image from the query args of a node.js http request object.

This function is asynchronous.

Node.js usage only.

bwipjs.toBuffer()

Usage

bwipjs.toBuffer(options[, callback])

Uses the built-in graphics drawing and zlib PNG encoding to return a barcode image in a node.js Buffer.

options are a bwip-js/BWIPP options object. callback is an optional callback handler with prototype:

function callback(err, png)
  • err is an Error object or string. If err is set, png is null.
  • png is a node Buffer containing the PNG image.

If callback is not provided, a Promise is returned.

Node.js usage only.

bwipjs.toCanvas()

Usage:

bwipjs.toCanvas(canvas, options)
bwipjs.toCanvas(options, canvas)

Uses the built-in graphics drawing. Identical to node.js toBuffer() rendering.

  • canvas can be an HTMLCanvasElement or an ID string or unique selector string.
  • options are a bwip-js/BWIPP options object.

The return value from toCanvas() is the actual HTMLCanvasElement.

This function is synchronous and throws on error.

Browser usage only.

bwipjs.fixupOptions()

Usage

bwipjs.fixupOptions(options)

Call this before passing your options object to a drawing constructor. For example:

// Draw the bar code with an SVG drawing object.
try {
	// fixupOptions() modifies options values (currently padding and
	// background color) to provide a simplified interface for the
	// drawing code.
	bwipjs.fixupOptions(opts);

	// The SVG drawing needs FontLib
	var svg = bwipjs.render(opts, DrawingSVG(opts, bwipjs.FontLib));
} catch (e) {
}

bwipjs.render()

Usage

bwipjs.render(options, drawing)

Renders a barcode using the provided drawing object.

This function is synchronous and throws on error.

See Annotated Example Drawing Object.

bwipjs.raw()

Usage

bwipjs.raw(options) 
bwipjs.raw(encoder, text, opts-string)

Invokes the low level BWIPP code and returns the raw encoding data.

This function is synchronous and throws on error.

See Notes on the Raw BWIPP Data.

bwipjs.loadFont()

Usage

bwipjs.loadFont(font-name, font-data)
bwipjs.loadFont(font-name, size-mult, font-data)
bwipjs.loadFont(font-name, height-mult, width-mult, font-data)
  • font-name : The name of the font.
  • size-mult : Sets the height-mult and width-mult to the same value.
  • height-mult :
  • width-mult : Used to adjust the height and width of the font to better match BWIPP font metrics. A value of 100 means no adjustment. A value less than 100 will decrease the dimension. A value greater than 100 will increase the dimension.
  • font-data : Can be a node.js Buffer, a Uint8Array, or a base64 encoded string that contains the font file data.

If the *-mult values are omitted, the font is rendered at its natural size.

To use a custom loaded font in your barcode images, set the font-name on the following BWIPP options:

  • textfont
  • addontextfont

addontextfont is only used for ISBN, ISMN, and ISSN barcodes. By default, they are rendered with OCR-A.

You can adjust the size of the font that BWIPP uses via the options:

  • textsize
  • addontextsize

The size values are in points.

Static Properties

bwipjs.BWIPJS_VERSION
bwipjs.BWIPP_VERSION

To Be Documented (bwip-js Internals)

bwipjs.BWIPJS
bwipjs.STBTT
bwipjs.FontLib
bwipjs.DrawingBuiltin(options)
bwipjs.DrawingCanvas(options, canvas)
bwipjs.DrawingZlibPng(options)