2017-05-23 16 views
21

我正嘗試在IPP(Internet打印協議)的第二個紙盤上打印文檔。我正在使用這個npm IPP-Library無法通過IPP在另一個紙盤上打印

但是,在任何時候我嘗試打印文檔時,我的打印機顯示一條消息,說明我需要將紙張添加到第一個紙盒和控制檯輸出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:它仍然困惑,並沒有任何線索如何解決這個問題。

+1

僅供參考:https://github.com/williamkapke/ipp/issues/43 – Sam

+0

感謝您引用問題我的代碼基於=)我完全忘了添加引用 – Batajus

回答

0

這已經有一段時間,因爲我要求幫助。感謝所有的貢獻=)

我嘗試了所有建議的解決方案從這裏和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

爲「媒體」的值包括中等名稱,中等大小,輸入 - 托盤和電子表格,使得一個屬性指定媒體。

4

看起來this pull request可能能夠解決您遇到的問題。直到ipp筆者合併拉請求,您可以更新您的NPM包在你的項目目錄中運行以下爲指向補丁:

npm i --save [email protected]:jaymcaliley/ipp 
0

給您發送的請求的響應與狀態代碼400發送到打印機的請求。

這裏可以看到on line 30

這可能是由防火牆配置或錯誤的網絡設置引起的。

您需要正確指定打印機的URL就像這個例子,並檢查該網址是否有效和打印機響應它:

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