Node JS - Use Printer (Hardware)

前端 未结 1 702
再見小時候
再見小時候 2020-12-14 04:27

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 rec

相关标签:
1条回答
  • 2020-12-14 04:41

    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.

    0 讨论(0)
提交回复
热议问题