Saturday, 10 June 2017

PrintToPDF not working in headless Chrome 60

I'm trying to experiment with PDF printing via headless Chrome. This is the error I'm dealing with:

(node:6761) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: PrintToPDF is not implemented

Node.js package:

html-pdf-chrome

Dependencies:

✔ "chrome-remote-interface": "^0.23.1"  (v0.23.2 installed)   
✔ Chrome 59  (v60 beta installed)

Driver script:

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 is installed and running in headless mode:

> google-chrome --version
Google Chrome 60.0.3112.24 beta

I've tracked down the code sections that calls Page.printToPDF which is where the error is raised:

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

I am able to perform other advertised functions like Page.captureScreenshot without fail.

How to get Page.printToPDF to perform as advertised?



via Drakes

No comments:

Post a Comment