节点JS-使用打印机(硬件) [英] Node JS - Use Printer (Hardware)
问题描述
我正在使用Angular JS和Node JS开发应用程序,我需要查看用户机器中所有可用的打印机,让用户选择其中一台并打印收据.
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?
推荐答案
我做了一个这样的应用程序.我使用 http ://nwjs.io/和注释中的模块: https://www.npmjs .com/package/printer ,这是此模块的工作代码,该模块在默认打印机中原始打印文件:
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();
您可以对其进行修改,以使用getPrinters()方法枚举所有已安装的打印机,然后允许用户选择所需的打印机.
you can adapt it to use the getPrinters() method to enumerate all installed printers and then allow the user to select the desired one.
这篇关于节点JS-使用打印机(硬件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!