我正在尝试在 node.js 中编写一个程序,该程序将允许用户将 docx 文件打印到打印机。
谁能告诉我它是如何在 Node.js 中完成的?
您可以使用节点打印机 https://www.npmjs.com/package/printer module.
以下是如何使用它来打印文件的示例:
// use: node printFile.js [filePath printerName]
var printer = require("printer"),
filename = process.argv[2] || __filename;
console.log('platform:', process.platform);
console.log('try to print file: ' + filename);
if( process.platform != 'win32') {
printer.printFile({filename:filename,
printer: process.env[3], // printer name, if missing then will print to default printer
success:function(jobID){
console.log("sent to printer with ID: "+jobID);
},
error:function(err){
console.log(err);
}
});
} else {
// not yet implemented, use printDirect and text
var fs = require('fs');
printer.printDirect({data:fs.readFileSync(filename),
printer: process.env[3], // printer name, if missing then will print to default printer
success:function(jobID){
console.log("sent to printer with ID: "+jobID);
},
error:function(err){
console.log(err);
}
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)