Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法通过IPP在其他纸盒上打印_Javascript_Node.js_Printing - Fatal编程技术网

Javascript 无法通过IPP在其他纸盒上打印

Javascript 无法通过IPP在其他纸盒上打印,javascript,node.js,printing,Javascript,Node.js,Printing,我正在尝试使用IPP(Internet打印协议)在第二个纸盘上打印文档。我在用这个 但在任何时候,我尝试打印文档时,我的打印机都会显示一条消息,说明我需要向第一个纸盘添加纸张,控制台的输出显示“打印:成功确定” var ipp = require("ipp"); var PDFDocument = require("pdfkit"); var concat = require("concat-stream"); var doc = new PDFDocument; doc.text("Hell

我正在尝试使用IPP(Internet打印协议)在第二个纸盘上打印文档。我在用这个

但在任何时候,我尝试打印文档时,我的打印机都会显示一条消息,说明我需要向第一个纸盘添加纸张,控制台的输出显示“打印:成功确定”

var ipp = require("ipp");
var PDFDocument = require("pdfkit");
var concat = require("concat-stream");

var doc = new PDFDocument;
doc.text("Hello World");

doc.pipe(concat(function (data) {
    var printer = ipp.Printer("MY_URL");

    var file = {
        "operation-attributes-tag": {
            "requesting-user-name": "admin",
            'attributes-charset': 'utf-8',
            'attributes-natural-language': 'de'
        },
        "printer-attributes": {
            "media-col": {
                "media-source": "tray-2"
            },
        },
        data: data
    };
    printer.execute("Print-Job", file, function (err, res) {
        console.log("Printed: " + res.statusCode);
    });
}));

doc.end();
我尝试的另一个变体如下(来自):

但是我得到了这个错误信息:

{ 
Error
    at new IppResponseError (/Users/alex/dev/print/printing/node_modules/ipp/lib/request.js:72:17)
    at ClientRequest.<anonymous> (/Users/alex/dev/print/printing/node_modules/ipp/lib/request.js:40:8)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:191:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:522:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
    at Socket.socketOnData (_http_client.js:411:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
  name: 'IppResponseError',
  statusCode: 400,
  message: 'Received unexpected response status 400 from the printer',
  stack: 'Error\n    at new IppResponseError (/Users/alex/dev/print/printing/node_modules/ipp/lib/request.js:72:17)\n    at ClientRequest.<anonymous> (/Users/alex/dev/print/printing/node_modules/ipp/lib/request.js:40:8)\n    at Object.onceWrapper (events.js:293:19)\n    at emitOne (events.js:96:13)\n    at ClientRequest.emit (events.js:191:7)\n    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:522:21)\n    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)\n    at Socket.socketOnData (_http_client.js:411:20)\n    at emitOne (events.js:96:13)\n    at Socket.emit (events.js:191:7)' }
400 'response'
{
错误
在新的IPPSResponseError(/Users/亚历克斯/dev/print/print/node\u modules/ipp/lib/request.js:72:17)
在ClientRequest上。(/Users/alex/dev/print/printing/node_modules/ipp/lib/request.js:40:8)
在Object.onceWrapper(events.js:293:19)
在emitOne(events.js:96:13)
在ClientRequest.emit(events.js:191:7)
在HTTPParser.parserOnIncomingClient[作为onIncoming](_http_client.js:522:21)
在HTTPParser.parserOnHeadersComplete(_http_common.js:99:23)
在Socket.socketOnData(_http_client.js:411:20)
在emitOne(events.js:96:13)
在Socket.emit(events.js:191:7)
名称:'IPResponseError',
状态代码:400,
消息:“收到来自打印机的意外响应状态400”,
stack:'Error\n在ClientRequest的新IppResponseError(/Users/alex/dev/print/printing/node\u modules/ipp/lib/request.js:72:17)\n在Object.onceWrapper(events.js:293:19)的ClientRequest.emit(events.js:96:13)\n在ClientRequest.emit(events.js:191:7)的堆栈中\n在HTTPParser.parserOnIncomingClient[作为onIncoming](\u http\u client.js:522:21)\n在HTTPParser.parserOnHeadersComplete(\u http\u common.js:99:23)\n在Socket.socketOnData(\u http\u client.js:411:20)\n在emitOne(events.js:96:13)\n在Socket.emit(events.js:191:7)}
400“回应”
我的打印机不支持IPP,但我在Macbook上共享了它,Macbook为所有共享打印机提供IPP服务。 如果我使用的是第一个纸盘,里面有纸,一切都很好,但对于我的项目来说,也有必要在其他纸盘上打印

Get Printer attributes
返回的属性列表在其他纸盘中列出了第二张纸作为受支持的
介质源,但仅第一张纸盘工作

有人知道如何在另一个纸盘上成功打印吗

更新:我还尝试了另一台打印机,但出现了相同的错误

更新22.06.17:它仍然很混乱,不知道如何修复

这似乎可以解决您遇到的问题。在
ipp
的作者合并拉取请求之前,您可以通过在项目目录中运行以下命令来更新npm包以指向该修补程序:

npm i --save ipp@github:jaymcaliley/ipp

对您发送的请求的响应与向打印机发出的请求的状态代码为400

这可以在这里看到

这可能是由防火墙配置或错误的网络设置引起的

您需要像本例中那样正确指定打印机的URL,并检查此URL是否有效以及打印机是否响应:

  var printer = ipp.Printer("http://NPI977E4E.local.:631/ipp/printer");

我已经有一段时间没有寻求帮助了。感谢大家的贡献=)

我尝试了这里和Github提供的所有建议解决方案,但都不起作用,但我找到了解决问题的解决方案

var ipp = require("ipp");
var PDFDocument = require("pdfkit");
var concat = require("concat-stream");

var doc = new PDFDocument;
doc.text("Hello World");

doc.pipe(concat(function (data) {
    var printer = ipp.Printer("MY_URL");

    var file = {
        "operation-attributes-tag": {
            "requesting-user-name": "admin",
            'attributes-charset': 'utf-8',
            'attributes-natural-language': 'de'
        },
        "printer-attributes": {
            // OLD WAY WHICH DOES NOT WORK
            //"media-col": {
            //    "media-source": "tray-2"
            //},
        },
        // SOLUTION 
        "job-attributes-tag":{
            "media":  ["tray-2"]
        },
        data: data
    };

    printer.execute("Print-Job", file, function (err, res) {
        console.log("Printed: " + res.statusCode);
    });

}));

doc.end();
我尝试了这一点,因为(4.2.11)是
media
描述的:

“介质”的值包括介质名称、介质大小和输入- 托盘和电子表单,以便一个属性指定介质


供参考:感谢您参考我的代码基于=)我完全忘了添加参考
var ipp = require("ipp");
var PDFDocument = require("pdfkit");
var concat = require("concat-stream");

var doc = new PDFDocument;
doc.text("Hello World");

doc.pipe(concat(function (data) {
    var printer = ipp.Printer("MY_URL");

    var file = {
        "operation-attributes-tag": {
            "requesting-user-name": "admin",
            'attributes-charset': 'utf-8',
            'attributes-natural-language': 'de'
        },
        "printer-attributes": {
            // OLD WAY WHICH DOES NOT WORK
            //"media-col": {
            //    "media-source": "tray-2"
            //},
        },
        // SOLUTION 
        "job-attributes-tag":{
            "media":  ["tray-2"]
        },
        data: data
    };

    printer.execute("Print-Job", file, function (err, res) {
        console.log("Printed: " + res.statusCode);
    });

}));

doc.end();