【发布时间】:2017-11-12 19:37:22
【问题描述】:
我正在尝试通过无头 Chrome 进行 PDF 打印。这是我正在处理的错误:
(node:6761) UnhandledPromiseRejectionWarning: 未处理的承诺 拒绝(拒绝 id:1):错误:PrintToPDF 未实现
Node.js 包:
html-pdf-chrome
依赖关系:
✔ "chrome-remote-interface": "^0.23.1" (v0.23.2 installed)
✔ Chrome 59 (v60 beta installed)
驱动脚本:
const htmlPdf = require('html-pdf-chrome');
const html = '<p>Hello, world!</p>';
const options = {
port: 9222, // port Chrome is listening on
};
htmlPdf.create(html, options).then((pdf) => pdf.toFile('test.pdf'));
Chrome 60 已安装并以无头模式运行:
> google-chrome --version
Google Chrome 60.0.3112.24 beta
我已经找到了调用 Page.printToPDF 的代码部分,这是引发错误的地方:
const CDP = require("chrome-remote-interface");
...
const { Page } = client;
...
// https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF
const pdf = yield Page.printToPDF(options.printOptions);
我能够执行其他宣传的功能,例如Page.captureScreenshot,而不会失败。
如何让Page.printToPDF 发挥宣传的作用?
【问题讨论】:
标签: node.js google-chrome pdf-generation google-chrome-devtools centos7