2013-04-24 65 views
1

我想在本地使用打印機打印PDF文件。這是一個代碼,試圖打印。nodejs的因特網打印協議(IPP)

fs.readFile('documents/AccountStatement.pdf', function(err, data) { 
    if (err) 
     throw err; 
    var printer = ipp.Printer("http://hostname:631/ipp/printer"); 
    var msg = { 
    "operation-attributes-tag": { 
     "requesting-user-name": "KUMA1936", 
     "job-name": "My Test Job", 
     "document-format": "application/pdf" 
    }, 
    data: data 
    }; 
    printer.execute("Print-Job", msg, function(err, res){ 
     console.log(res); 
     console.log(err); 
    }); 
}); 

在上面的代碼中,printer.execute()方法和「Print-Job」參數是什麼。又是什麼631 here.When我打印資源,其節目

{版本:「1.1」, 的StatusCode:「服務器錯誤操作不支持」, ID:442076, 「操作屬性-tag': { '屬性,字符集': 'UTF-8', '屬性 - 自然語言': 'EN-US'}} ERR爲空。

回答

0

您可以檢查API docs。第一個參數(字符串)是由IPP定義的操作。 說明有關Print-Job操作被賦予here

3.2.1 Print-Job Operation 

    This REQUIRED operation allows a client to submit a print job with 
    only one document and supply the document data (rather than just a 
    reference to the data). See Section 15 for the suggested steps for 
    processing create operations and their Operation and Job Template 
    attributes. 

你可以看到其他的IPP支持的操作here。 631是用於IPP的公認端口,它使用TCP。

您可以查看有關該錯誤here,其中顯示:

13.1.5.2 server-error-operation-not-supported (0x0501) 

    The IPP object does not support the functionality required to fulfill 
    the request. This is the appropriate response when the IPP object 
    does not recognize an operation or is not capable of supporting it. 
    See sections 3.1.6.1 and 3.1.7. 

這意味着,在你的代碼中沒有錯誤。很可能您的打印機未配置或不支持IPP。最後但並非最不重要的,必須給IPP.Printer打印機IP。因此,請檢查您提供的IP是否有效(您的代碼顯示您提供了主機名)。從page它被賦予的項目:

To find out if your printer supports IPP: 

- Google your printer's specs 
- Try: telnet YOUR_PRINTER 631. If it connects, that's a good sign. 
- Use the '/examples/findPrinters.js' script. 
0

在我來說,我只是份額打印機:(喜歡與他人分享)

那麼URL會是(你會被findPrinters.js找到)

http://My-Computer-Name.local.:631/printers/my_printer_name

這應該是幫助,如果您的打印機donesnt與電腦連接(如USB)。但通過局域網連接。

0
  • 看起來就像您在發送IPP-2.0時獲得IPP-Version-1.1-Response一樣。
  • 嘗試使用版本選項降級到1.1