简体   繁体   English

用于nodejs的Internet打印协议(IPP)

[英]Internet Printing Protocol (IPP) for nodejs

I am trying print the pdf file in my local using printer. 我正在尝试使用打印机在本地打印pdf文件。 This is a code, tried to print. 这是一个代码,尝试打印。

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

In the above code what does printer.execute() method and "Print-Job" parameter. 在上面的代码中,printer.execute()方法和“ Print-Job”参数有什么作用。 And what does 631 here.When i print the res,its shows 还有631在这里做什么。当我打印res时,它显示

{ version: '1.1', statusCode: 'server-error-operation-not-supported', id: 442076, 'operation-attributes-tag': { 'attributes-charset': 'utf-8', 'attributes-natural-language': 'en-us' } } err is null. {版本:“ 1.1”,statusCode:“服务器错误操作不受支持”,id:442076,“ operation-attributes-tag”:{“ attributes-charset”:“ utf-8”,“ attributes-natural -language':'en-us'}} err为空。

You can check the API docs . 您可以检查API 文档 The first parameter (string) is an operation defined by IPP. 第一个参数(字符串)是IPP定义的操作。 Description about Print-Job operation is given here 此处给出有关Print-Job操作的说明

 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. 

You can see other IPP supported operations here . 您可以在此处查看其他IPP支持的操作。 631 is the accepted port used for IPP, which uses TCP. 631是IPP接受的端口,该端口使用TCP。

You can check more about the error here , which shows : 您可以在此处查看有关该错误的更多信息,该错误显示:

 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. 

This means that there is no error in your code. 这意味着您的代码中没有错误。 Most likely your printer is not configured or does not support IPP. 您的打印机很可能未配置或不支持IPP。 Last but not the least, the IPP.Printer has to be given the printer IP. 最后但并非最不重要的IPP.Printer是,必须为IPP.Printer赋予打印机IP。 So check the IP you are giving is valid (your code shows you gave hostname). 因此,请检查您提供的IP是否有效(您的代码显示您提供的主机名)。 From the project page it is given : 从项目页面可以看到:

 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. 

In my case i just share the printer : (like share with another) 就我而言,我只是共享打印机:( 就像与其他人共享)

So URL gonna be (you will be found by findPrinters.js) 因此,URL将成为 (您将通过findPrinters.js找到)

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

This should be help if your printer donesnt connect (like USB) with your computer. 如果您的打印机完成了与计算机的连接(如USB),这将对您有所帮助。 But connect via lan. 但是通过局域网连接。

  • Look's like you get an IPP-Version-1.1-Response while sending IPP-2.0. 看起来您在发送IPP-2.0时获得了IPP-Version-1.1-Response。
  • Try downgrading to 1.1 by using the version-option 尝试通过使用version-option降级到1.1

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

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