我使用pdfkitipp库将PDF打印到网络打印机(Brother HL-L2360D series).

以下是代码

const ipp = require('ipp');
const concat = require('concat-stream');
const PDFDocument = require('pdfkit');

const doc = new PDFDocument({ margin: 0 });
doc.text('Testing Printing Functionality. Sent By Developer', 0, 780);

doc.pipe(concat(function (pdf) {
    const printer = ipp.Printer('http://printer.sandbox.com/ipp/print');
    const msg = {
        'operation-attributes-tag': {
            'requesting-user-name': 'William',
            'job-name': 'My Test Job',
            'document-format': 'application/octet-stream'
        },
        data: pdf
    };
    printer.execute('Print-Job', msg, function (err, res) {
        console.log({ err, res });
    });
}));
doc.end();

但它打印了一些随机字符

image

当我通过发送Get-Printer-Attributes操作判断打印机配置时.它返回以下受支持的有效文档列表.我看它没有application/pdf.出于这个原因,我将application/octet-stream作为document-format发送.

{
    "version": "2.0",
    "statusCode": "successful-ok",
    "id": 31208186,
    "operation-attributes-tag": {
        "attributes-charset": "utf-8",
        "attributes-natural-language": "en-us"
    },
    "printer-attributes-tag": {
        "copies-default": 1,
        "finishings-default": "none",
        "printer-info": "en\u001eBrother HL-L2360D series",
        "printer-make-and-model": "en\u001eBrother HL-L2360D series",
        "ipp-versions-supported": [
            "1.0",
            "1.1",
            "2.0"
        ],
        "operations-supported": [
            "Print-Job",
            "Validate-Job",
            "Create-Job",
            "Send-Document",
            "Cancel-Job",
            "Get-Job-Attributes",
            "Get-Jobs",
            "Get-Printer-Attributes",
            "Identify-Printer"
        ],
        "multiple-document-jobs-supported": false,
        "multiple-operation-time-out": 150,
        "natural-language-configured": "en",
        "charset-configured": "utf-8",
        "charset-supported": "utf-8",
        "document-format-supported": [
            "application/octet-stream",
            "image/urf",
            "image/pwg-raster"
        ],
        "document-format-default": "application/octet-stream",
        "printer-is-accepting-jobs": false,
        "queued-job-count": 1,
        "pdl-override-supported": "attempted",
        "printer-up-time": 14285,
        "compression-supported": "none",
        "color-supported": false,
        "landscape-orientation-requested-preferred": 5,
        "marker-colors": "en\u001e#000000",
        "marker-high-levels": 100,
        "marker-levels": 100,
        "marker-low-levels": 10,
        "marker-names": "en\u001eBK",
        "marker-types": "toner",
        "media-bottom-margin-supported": 432,
        "media-left-margin-supported": 432,
        "media-right-margin-supported": 432,
        "media-source-supported": [
            "auto",
            "manual",
            "tray-1"
        ],
        "media-top-margin-supported": 432,
        "media-type-supported": [
            "stationery",
            "stationery-lightweight",
            "stationery-heavyweight",
            "stationery-cover",
            "envelope",
            "envelope-heavyweight",
            "envelope-lightweight",
            "stationery-recycled",
            "labels",
            "stationery-bond"
        ]
    }
}

我不确定我做错了什么.有没有人能帮帮我?

我试着换了document-format元.已try 先创建作业(job),然后再执行它.我也试过使用iip://printer.sandbox.com/ipp/print,问题仍然是一样的.

推荐答案

"打印机制造商",通常会有一系列的打印机,以适应其市场的不同部分.反过来,这些范围可能针对不同的操作系统和服务器.

一般情况下,"商务打印机"将使用PostScript或打印机控制语言,较少使用更有问题的板载PDF计算引擎.

OP问题中的sibling 模型在manual中显示它使用的是PCL而不是PS

为了将PDF转换成PCL,它需要通过转换器进行解析,转换器可以是带有PCL打印驱动程序的Acrobat PDF Reader等应用程序,也可以直接通过Ghost脚本/Ghost PDL(两者都不是免费的商业用途)进行解析.

Node.js相关问答推荐

当变量在另一个文件中初始化时,在初始化错误之前无法访问变量

即使卷已设置,Docker Nodemon 也不会热重载

如何在docker容器上正确安装nodejs?

Node fetch 实现似乎与 Deno 和 Bun 不同,导致网站没有返回响应?

是否可以在 NodeJS 代码库中的每个函数之前和之后添加 console.log?

TypeScript Eslint警告了一个AWS客户端构造函数(dynamodb),但没有警告另一个(s3)

表达 js 错误处理程序在第一个之后被忽略

Angular Build 生产返回致命的 javascript 无效大小错误

Axios 响应循环通过函数只返回第一个映射对象的结果

使用react 组件加载特定 DIV 而无需重新加载整个页面

使用Typescript 时我应该避免循环导入吗?

在express js模型中将js转换为Typescript 时Typescript 错误

Mongoose,如何一次更新多个?

如何在 MongoDB collection.find() 上获取回调

我们如何或可以通过 npm 和 Meteor 使用 node 模块?

将变量传递给nodemailer中的html模板

为什么我们要为 Angular 2.0 安装 Node.js?

如何使用 Node.js 在服务器端管理多个 JS 文件

Bootstrap 中的 Grunt 依赖冲突

- configuration.output.path:提供的值public不是绝对路径!使用 Webpack