-
Notifications
You must be signed in to change notification settings - Fork 304
Methods Reference
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.
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. Iferr
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.
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.
This function is synchronous and throws on error.
Browser usage only.
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 drawing needs FontLib
var drawing = DrawingSVG(opts, bwipjs.FontLib);
bwipjs.render(opts, drawing);
} catch (e) {
}
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.
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.
Usage
bwipjs.loadFont(font-name, width-mult, height-mult, buffer)
-
font-name
: The name of the font. -
width-mult
: -
height-mult
: Used to adjust the width and height 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. -
buffer
: Can be a node.js Buffer, a Uint8Array, or a base64 encoded string that contains the font file data.
To use a custom loaded font in your barcode images, you must 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.
bwipjs.VERSION
bwipjs.BWIPP.VERSION
bwipjs.BWIPJS
bwipjs.BWIPP
bwipjs.STBTT
bwipjs.FontLib
bwipjs.DrawingBuiltin(options)
bwipjs.DrawingCanvas(options, canvas)
bwipjs.DrawingZlibPng(options)