Generate 50+ different 1D or 2D barcodes in png, eps, or svg format.
- 1. Introduction
- 2. Installation
- 3. Usage
- 4. Available options (struct)
- 5. Error handling
- 6. Symbology types
- 7. Development
- 8. Credits
- 9. License
This Node.js module will allow you to generate over 50+ different types of 1D or 2D symbologies, including barcodes for books, grocery, shipping carriers, healthcare, and international codes. It can save a png, svg, or eps image, or render a base64 png bitmap.
symbology can be downloaded directly or installed via npm.
npm install symbology --save
var symbology = require('symbology');
Prepare a Symbol json object with your desired settings (see 4. Available options (struct) for more info):
var Symbol = {
symbology: symbology.Barcode.CODE128,
foregroundColor: 'fff000',
backgroundColor: '000000',
fileName: '/my/directory/barcode.png'
};
Each function returns a promise that completes with an object containing the exit code and message of the function (see 5. Error handling for more info).
createStream(Symbol, data, type)
Writes a base64 string to the output object in a property data
.
Parameter | Type | Values |
---|---|---|
Symbol |
Struct |
Struct of symbology settings |
data |
String |
Desired data to encode |
symbology
.createStream(Symbol, '12345')
.then(function(data) {
console.log('Result: ', data);
}, function(err) {
console.log('Error: ', err);
});
Returns:
Result: {
message: '',
code: 0,
data: 'data:image/png;base64,iVBOR [...] g=='
}
createFile(Symbol, data)
Writes a stream in to the output object in a property data
.
Parameter | Type | Values |
---|---|---|
Symbol |
Struct |
Struct of symbology settings |
data |
String |
Desired data to encode |
symbology
.createFile(Symbol, '12345')
.then(function(data) {
console.log('Result: ', data);
}, function(err) {
console.log('Error: ', err);
});
This creates a file in the specified fileName
and will log:
Result: {
message: '',
code: 0,
fileName: 'barcode.png'
}
A Symbol is a regular JavaScript object with the following available properties:
Enumerated type | Type | Meaning | Required? | Default value |
---|---|---|---|---|
symbology | Symbology enum | The enumerated type of the symbology (see [Enumerated Barcode Types] for more info). | Yes | |
height | Number | The height of the image. If specified, this will maintain the aspect ratio. | No | 50 |
whitespaceWidth | Number | Width of whitespace, for barcodes which have this option. | No | 0 |
borderWidth | Number | Width of border. | No | 0 |
outputOptions | Number | Symbology-specific output option. | No | NULL |
foregroundColor | Hexadecimal number | Barcode foreground color. | No | #FFFFFF |
backgroundColor | Hexadecimal number | Barcode background color. | No | #000000 |
fileName | String | Full path to the file to render. | Yes* | |
scale | Number | Scale of the barcode image. Applies only to PNG. | No | 1.0 |
option1 | Number | Symbology-type-specific option value. | No | NULL |
option2 | Number | Symbology-type-specific option value. | No | NULL |
option3 | Number | Symbology-type-specific option value. | No | NULL |
* required only if using createFile
.
Each function returns an object having property code
, which is the status code of the function, and message
, which contains an error/warning message (if any).
Below are the possible status codes:
Code | Enumerated type | Meaning |
---|---|---|
2 | ZWARN_INVALID_OPTION | One or more options are invalid but the barcode was created anyway. |
5 | ZERROR_TOO_LONG | The file path was too long. |
6 | ZERROR_INVALID_DATA | The data for the specified symbology is invalid. |
7 | ZERROR_INVALID_CHECK | Error checking (if any) on the rendered barcode failed. |
8 | ZERROR_INVALID_OPTION | One or more options are invalid and rendering failed. |
9 | ZERROR_ENCODING_PROBLEM | Invalid characters in input data. |
10 | ZERROR_FILE_ACCESS | Cannot write to the given path. |
11 | ZERROR_MEMORY | Corrupt or insufficient memory. |
There are 53 different available symbology types. For an exhaustive list, please see the Barcode Types list.
To compile the latest, ensure you have node-pre-gyp installed. Then run:
npm run build
npm test
npm run package-binary
Replace report all bugs here.
Available here.
This library is a JS/C++ wrapper module for the terrific C/C++ library Zint, (C) Robin Stuart. Module by Josh Shor.
MIT.