MatteoMeil / node-native-printer

Node module to print from nodejs apps
83 stars 41 forks source link

Can you add tha ability to print Canvas #11

Open sebmahel opened 5 years ago

sebmahel commented 5 years ago

Example

const JsBarcode = require('jsbarcode'); const Canvas = require("canvas"); const printer = require('node-native-printer');

let canvas = Canvas.createCanvas(); JsBarcode(canvas, "Hello");

let options = { "collate": true, "landscape": true, "paperSize": "Letter" }

printer.printCanvas(canvas, options, 'PrinterName')

sebmahel commented 5 years ago

//Workarround

const fs = require('fs'); const os = require('os'); const JsBarcode = require('jsbarcode'); const Canvas = require("canvas"); const printer = require('node-native-printer');

let canvas = Canvas.createCanvas(); JsBarcode(canvas, "Hello");

var buf = canvas.toBuffer(); fs.writeFileSync( os.tmpdir() + "/tmp.png", buf);

let options = { "collate": true, "landscape": true, "paperSize": "Letter" }

printer.print(os.tmpdir() + "/tmp.png", options, 'PrinterName')