简体   繁体   English

节点打印机无法在网络打印机中打印(node.js)

[英]node-printer not printing in net printer (node.js)

I'm trying to send directly documents to my printer. 我正在尝试直接将文档发送到打印机。 I have used node-printer and have not error, but printer is not receiving anything. 我使用过节点打印机,但没有错误,但是打印机没有收到任何信息。 This is my code: 这是我的代码:

var printer = require("printer");
    filename = process.argv[2] || __filename;

console.log('platform:', process.platform);
console.log('default printer name: ' + (printer.getDefaultPrinterName() || 'is not defined on your computer'));
console.log('try to print file: ' + filename);

if( process.platform != 'win32') {
    printer.printFile({filename:filename,
    printer: process.env[3], 
    success:function(jobID){
       console.log("sent to printer with ID: "+jobID);
    },
    error:function(err){
       console.log(err);
    }
});

} else {
  var fs = require('fs');
  printer.printDirect({
    data:fs.readFileSync(filename).toString(),
    printer: process.env[3], 
    type: 'RAW',
    success:function(jobID){
      console.log("sent to printer with ID: "+jobID);
    },
    error:function(err){
      console.log(err);
    }
});

I test do "node print.js lorem.txt" and it looks like document is sent to print queue, but net printer is not receiving anything. 我测试了“ node print.js lorem.txt”,它看起来像文档已发送到打印队列,但是网络打印机什么都没收到。

By the way, I'm working on Windows 10. 顺便说一句,我正在使用Windows 10。

您正在使用printer: process.env[3]指定打印机,但由于要在控制台中写入printer.getDefaultPrinterName() ,因此您似乎要使用默认打印机,因此请尝试删除printer: process.env[3],并使模块在默认打印机中打印,然后查看是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM