inspired from https://gitlab.pagedmedia.org/tools/pagedjs-cli/blob/master/index.js
This implement a Printer class that extend EventEmitter which does:
- browser = puppeteer.launch()
- page = browser.newPage()
- Serving the paged html locally
/print
the website/polyfill
les scripts js
- page.goto(
http://localhost:${port}/print/${basename}
) locally served files - page.exposeFunction source
- Create a binding: send('Runtime.addBinding', {name: name}) source
- that would trigger an event
client.on('Runtime.bindingCalled', event => this._onBindingCalled(event));
- also after
this._client.send('Page.addScriptToEvaluateOnNewDocument', {source: expression});
- So it
page.exposeFunction('PuppeteerLogger', (msg, counter)
then, page.exposeFunction('onPagesRendered', async (msg, width, height, orientation)
that emit the message- Add local paged.js
await page.addScriptTag({ url: `http://localhost:${port}/polyfill/paged.polyfill.js` });
- This lead to there
- This add the script.
page.waitForSelector(".pagedjs_pages")
: Waiting for a class in the page
settings = {
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: options.width ? false : true,
width: options.width,
height: options.height,
orientation: options.orientation,
margin: {
top: 0,
right: 0,
bottom: 0,
left: 0,
}
}
const result = await this._client.send('Page.printToPDF', {
page.waitForSelector(".pagedjs_pages")
- Pagedjs implement
window.PuppeteerLogger("page")
andwindow.onPagesRendered(msg, styles.width.value + styles.width.unit, styles.height.value + styles.height.unit, styles.orientation);
- If we can get back those information into R, it would help.