Node JS - Use Printer (Hardware)

30,951

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.

Share:
30,951

Related videos on Youtube

Agustín
Author by

Agustín

I created my first web page at the age of 9 - it was dedicated to one of my favorite band. As any person’s first attempt at anything, it was not good. In fact, it was cringe-worthy bad, and I had never been so proud of anything in my life. It’s been such an enjoyable ride since then, doing what I love for a living and constantly learning more about it. I now have over 5 years’ experience in the development of web and mobile applications, both in frontend and backend side. I have an extensive knowledge of most used web technologies and frameworks such as HTML5, CSS3, JavaScript, Angular JS, Typescript, Node JS, Mongo DB, among many others. I’ve also been a part of a variety of demanding projects, ranging from small, local endeavors, to complex, international platforms and highly customized migrations working with Agile Methodologies. I’ve tried my hand at a number of challenges, becoming more flexible and versatile with every new lesson learnt. I’ve realized I’m most comfortable working in any-size international teams, as I’ve found I thrive in a collaborative environment

Updated on July 09, 2022

Comments

  • Agustín
    Agustín almost 2 years

    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?

    • edsadr
      edsadr almost 9 years
      Hey Agustin... es suficiente con mi respuesta o todavía estas atascado?
    • Agustín
      Agustín almost 9 years
      No lo he intentado aún, pero parece que funcionaría, en un rato te digo. gracias!