Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFileSync('fonts/Inconsolata.otf', 'binary'));
http.createServer(function(req, res) {
// If the url does not begin /?bcid= then 404. Otherwise, we end up
// returning 400 on requests like favicon.ico.
if (req.url!.indexOf('/?bcid=') != 0) {
res.writeHead(404, { 'Content-Type':'text/plain' });
res.end('BWIPJS: Unknown request format.', 'utf8');
} else {
bwipjs(req, res);
}
}).listen(3030);
bwipjs.toBuffer({
bcid: 'code128', // Barcode type
text: '0123456789', // Text to encode
scale: 3, // 3x scaling factor
height: 10, // Bar height, in millimeters
includetext: true, // Show human-readable text
textxalign: 'center', // Always good to set this
textfont: 'Inconsolata', // Use your custom font
textsize: 13 // Font size, in points
}, function (err:string|Error, png: Buffer) {
if (err) {
console.log(err);
} else {
// `png` is a Buffer
// png.length : PNG file length
// png.readUInt32BE(16) : PNG image width
// png.readUInt32BE(20) : PNG image height
.then((next) => {
debug('New barcode generation start...');
var url = `http://localhost/#/forms/filings/${uid(15)}`;
var id = url.substring(url.lastIndexOf('/') + 1,url.length);
fileName = `${id}-${fileName}`;
bwipjs.toBuffer({
bcid: 'code128', // Barcode type
text: url, // Text to encode
scaleX: 2, // 2x scaling factor
scaleY: 1, // 1y scaling factor
includetext: false, // Show human-readable text
textxalign: 'center', // Always good to set this
}, function (err, png) {
if (err) {
console.error(err);
} else {
PNG = png;
next();
}
});
})
return new Promise((resolve, reject) => {
bwipjs.toBuffer({
bcid: 'pdf417',
text: content,
backgroundcolor: 'ffffff',
}, (err, png) => {
if (err) {
reject(err)
} else {
resolve(png)
}
})
})
}