gpt4 book ai didi

node.js - Nodejs 的互联网打印协议(protocol) (IPP)

转载 作者:太空宇宙 更新时间:2023-11-03 22:18:10 25 4
gpt4 key购买 nike

我正在尝试使用打印机在本地打印 pdf 文件。这是一段代码,已尝试打印。

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 是什么意思。当我打印资源时,它显示

{ 版本:'1.1', statusCode: '服务器错误操作不支持', 编号: 442076, '操作属性标签': { '属性字符集': 'utf-8', '属性自然语言': 'en-us' } }错误为空。

最佳答案

您可以查看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.

关于node.js - Nodejs 的互联网打印协议(protocol) (IPP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16194758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com