i am totally new to node and all.. my basic problem is can i create code128 barcode in it... i am not able to figure out how
They are supported only QR codes. Other codes you can insert into the PDF as an image that you prepare in a different library.
@liborm85
Thanks for the response but i have finally managed to do it through barcode generator
var Barc = require('barcode-generator')
,barc = new Barc();
var awb = "<Tracking Number>";
//create a 300x200 px image with the barcode 1234
var buf = barc.code128(awb, width=200, height=100);
and in docDefinition just added
header("Scan for the Tracking "),
content: [
{
image: buf,
}, '\n',
]
barcode-generator library did not work for me, because of error 'Canvas is not a constructor' inside one of barcode-generator's files.
So I used another library (https://www.npmjs.com/package/jsbarcode) that let me pass my own canvas instance created the way I wanted...
// import jsbarcode library and Canvas
var JsBarcode = require('jsbarcode');
const { createCanvas } = require('canvas');
const canvas = createCanvas(0, 0);
// create a bar code with the number/text I want and populate the canvas with it..
JsBarcode(canvas, '123456');
// draw the code bar on pdfmake as an image...
{ image: canvas.toDataURL(), width: 80, height: 40 }, // bar code as image
That's it!
barcode-generator library did not work for me, because of error 'Canvas is not a constructor' inside one of barcode-generator's files.
So I used another library (https://www.npmjs.com/package/jsbarcode) that let me pass my own canvas instance created the way I wanted...
// import jsbarcode library and Canvas
var JsBarcode = require('jsbarcode');
const { createCanvas } = require('canvas');const canvas = createCanvas(0, 0);
// create a bar code with the number/text I want and populate the canvas with it..
JsBarcode(canvas, '123456');// draw the code bar on pdfmake as an image...
{ image: canvas.toDataURL(), width: 80, height: 40 }, // bar code as imageThat's it!
Hi @Girdacio,
could you tell how to import jsBardcode library and canvas
i have installed it but i dont know where and how to import
Most helpful comment
barcode-generator library did not work for me, because of error 'Canvas is not a constructor' inside one of barcode-generator's files.
So I used another library (https://www.npmjs.com/package/jsbarcode) that let me pass my own canvas instance created the way I wanted...
// import jsbarcode library and Canvas
var JsBarcode = require('jsbarcode');
const { createCanvas } = require('canvas');
const canvas = createCanvas(0, 0);
// create a bar code with the number/text I want and populate the canvas with it..
JsBarcode(canvas, '123456');
// draw the code bar on pdfmake as an image...
{ image: canvas.toDataURL(), width: 80, height: 40 }, // bar code as image
That's it!