【问题标题】:Cannot print on another paper tray via IPP无法通过 IPP 在另一个纸盘上打印
【发布时间】:2017-10-23 23:00:19
【问题描述】:

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

但在任何时候我尝试打印文档时,我的打印机都会显示一条消息,我需要将纸张添加到第一个纸盘,并且控制台输出显示 Printed: successful-ok

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();

我尝试的另一个变体如下(来自here):

var PDFDocument = require("pdfkit");
let fs = require('fs')
var ipp = require('ipp');
var uri = "http://10.1.205.71";


var msg = new Buffer(
  '0200'+ //Version
  '000201e6d5f2'+
  '01'+ //Operation attributes tag (your information in the Operation attributes might be different)
    '47'+ //charset tag
    '0012'+ //length
    '617474726962757465732d63686172736574'+ //attributes-charset
    '0005'+ //length
    '7574662d38'+ //utf-8
    '48'+ //natural language tag
    '001b'+ //length
    '617474726962757465732d6e61747572616c2d6c616e6775616765'+//attributes-natural-language
    '0002'+//length
    '656e'+ //en
    '45'+ // URI tag
    '000b'+ //length
    '7072696e7465722d757269'+ //printer-uri
    '0012'+//length
    '687474703a2f2f31302e312e3230352e3731'+//http://10.1.205.71
    '49'+ //mimeMediaType tag
    '000f'+ //length
    '646f63756d656e742d666f726d6174'+ //document format
    '000f'+ //length
    '6170706c69636174696f6e2f706466'+ //application/pdf
  '02'+ //job attributes tag
    '34'+ //begin collection
      '0009'+ //length
      '6d656469612d636f6c'+ //media-col
      '0000'+ //value length
      '4a'+ //collection entry
      '0000'+ //name length
      '000c'+ //value length
      '6d656469612d736f75726365'+ //media-source
      '44'+ // collection entry
      '0000'+ //name length
      '0006'+ //value length
      '747261792d32'+ //tray-2
    '37'+ //end of collection
    '00000000'+ //name length and value length
  '03', 'hex');

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

var buffers = [];
doc.on('data', buffers.push.bind(buffers));
doc.on('end', function(){
  var buf = Buffer.concat(buffers);
  var catBuf = Buffer.concat([msg, buf]);
  ipp.request(uri, catBuf, function(err, res){
    if(err){
      return console.log(err);
    }
    console.log(JSON.stringify(res,null,2));
  });
});
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'

我的打印机不支持 IPP,但我在我的 Macbook 上共享它,它为所有共享打印机提供 IPP 服务。 如果我使用第一个纸盘并且里面有纸,一切都很好,但对于我的项目,也有必要在其他纸盘上打印。

Get-Printer-Attributes 返回的属性列表在其他纸盘中列出了支持media-source 的第二个纸盘,但只有第一个纸盘有效。

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

更新:我也尝试了另一台打印机,但我得到了同样的错误。

22.06.17 更新:它仍然很困惑,不知道如何解决这个问题。

【问题讨论】:

标签: javascript node.js printing


【解决方案1】:

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

我从这里和 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();

我试过这个,因为 here (4.2.11) 是 media 描述为:

“媒体”的值包括中等名称、中等大小、输入- 托盘和电子表格,以便一个属性指定媒体。

【讨论】:

    【解决方案2】:

    对您发送的请求的响应是状态代码为 400 的对已发出到打印机的请求的响应。

    可以在这里看到on line 30

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

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

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

    【讨论】:

      【解决方案3】:

      看来this pull request 或许能够解决您遇到的问题。在ipp 的作者合并拉取请求之前,您可以通过在项目目录中运行以下命令来更新您的 npm 包以指向该补丁:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多