Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node JS - Use Printer (Hardware)

I'm developing an application with Angular JS and Node JS where I need to see all available printers in the user's machine, let the user select one of them and print a receipt.

Is there a way to achieve this?

like image 831
Agustín Avatar asked Aug 13 '15 00:08

Agustín


1 Answers

I did an application like that.. I did it using http://nwjs.io/ and the module in the comment: https://www.npmjs.com/package/printer, here is a working code with this module printing raw in the default printer a file:

var printer = require('printer');
var fs = require('fs');

var info = fs.readFileSync('ticket.txt').toString();

function sendPrint() {
  printer.printDirect({
    data: info,
    type: 'RAW',
    success: function (jobID) {
      console.log("ID: " + jobID);
    },
    error: function (err) {
      console.log('printer module error: '+err);
      throw err;
    }
  });
}

sendPrint();

you can adapt it to use the getPrinters() method to enumerate all installed printers and then allow the user to select the desired one.

like image 182
edsadr Avatar answered Oct 30 '22 14:10

edsadr