Barcode Bakery is a library written in Node.JS, .NET Standard and PHP which allows you to generate barcodes on the fly on your server for displaying or saving.
The library has minimal dependencies in each language in order to be supported on a wide variety of web servers.
The library is available for free for non-commercial use; however you must purchase a license if you plan to use it in a commercial environment.
Installation
There are two ways to install our library:
- Run the following command:
$ npm install @barcode-bakery/barcode-1d @barcode-bakery/barcode-common
Requirements
Example usages
For a full example of how to use each symbology type, visit our API page.
You can also visit the GitHub example page.
Displaying a Code 128 on the screen
import { createServer } from 'http';
import { parse } from 'querystring';
import { BCGColor, BCGDrawing, BCGFont } from '@barcode-bakery/barcode-common';
import { BCGcode128 } from '@barcode-bakery/barcode-1d';
const defaultText = 'a123';
let font = new BCGFont('Arial', 18);
let colorBlack = new BCGColor(0, 0, 0);
let colorWhite = new BCGColor(255, 255, 255);
let getDrawing = function (text) {
let drawException = null,
barcode = null;
try {
let code = new BCGcode128();
code.setScale(2);
code.setThickness(30);
code.setBackgroundColor(colorWhite);
code.setForegroundColor(colorBlack);
code.setFont(font);
code.setStart(null);
code.setTilde(true);
code.parse(text);
barcode = code;
} catch (exception) {
drawException = exception;
}
let drawing = new BCGDrawing(barcode, colorWhite);
if (drawException) {
drawing.drawException(drawException);
}
return drawing;
};
createServer(function (request, response) {
let drawing = getDrawing(parse(request.url).query?.toString() || defaultText);
drawing.toBuffer(BCGDrawing.ImageFormat.Png, function (err, buffer) {
response.writeHead(200, { 'Content-Type': 'image/png' });
response.end(buffer);
});
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
Saving the image to a file
Replace the last lines of the previous code with the following:
let drawing = new BCGDrawing(code, colorWhite);
drawing.save('image.png', BCGDrawing.ImageFormat.Png, function () {
console.log('Done.');
});
This will generate the following:
Sync methods
Both save
and toBuffer
have counterparts acting synchronously: saveSync
and toBufferSync
.
Tests
Simply type npm test
to run the tests.
Supported types
Other libraries available for purchase