4 ms·
I was playing around with Puppeteer the other day and was wondering if it was possible to render a web page to a single page PDF (a page with fixed width and va
by renke1 9y ago
I was playing around with Puppeteer the other day and was wondering if it was possible to render a web page to a single page PDF (a page with fixed width and variable height). Basically like creating screenshot without losing the text information. This would solve a lot problems such as sticky elements hiding text like in this example [1].
[1]: https://url-to-pdf-api.herokuapp.com/api/render?url=https://hackernoon.com/why-isnt-agile-working-d7127af1c552 https://url-to-pdf-api.herokuapp.com/api/render?url=https://...
- kimmobru 9y agoThat's a good idea! You can achieve this by adding e.g. &pdf.width=1000px&pdf.height=10000px parameters. Sometimes you can get rid of the sticky headers with &emulateScreenMedia=false parameter if the page has well implemented @media print rules in CSS. We decided to use page.emulateMedia('screen') with Puppeteer to make PDFs look more like the actual web page by default. Pages which use lazy loading for images may look incorrect when rendered. &scrollPage=true parameter may help with this. It scrolls the page to the bottom before rendering the PDF. Using these options make the PDF better: https://url-to-pdf-api.herokuapp.com/api/render?url=https://hackernoon.com/why-isnt-agile-working-d7127af1c552&emulateScreenMedia=false&scrollPage=true https://url-to-pdf-api.herokuapp.com/api/render?url=https://...
- sid- 9y agoI bet that breaks on infinite scroll pages ?