简体   繁体   中英

how to convert number to bar code using cloudfunction and nodejs

how to implement this jsbarcode npm on convert phone or mobile number to bar code using cloud function and nodejs

var jsbarcode = require("jsbarcode")
<img id="barcode"/>
$("#barcode").JsBarcode("Hi!");
JsBarcode("#barcode", "1234", {
  format: "pharmacode",
  lineColor: "#0aa",
  width:4,
  height:40,
  displayValue: false
});

For using JsBarcode in NodeJS, you need canvas ( node-canvas ), not HTML image tag.

Install canvas

npm install canvas

Then use it with jsbarcode

const JsBarcode = require('jsbarcode');
const { Canvas } = require("canvas");

const number = getNumberFromWherever()

// Create a new canvas
const canvas = new Canvas();
JsBarcode(canvas, number, {
  format: "pharmacode",
  lineColor: "#0aa",
  width:4,
  height:40,
  displayValue: false
});

// Get Data URL and save it to the DB

canvas.toDataURL('image/png', (err, png) => {
  // Do whatever you want to do
  // for storing in the DB
})

Please refer node-canvas GitHub page for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM