3 ms·
This is great, but it's sobering to see how hard it is to get a nice, "complete" PDF screenshot out of a modern site. Here's a quick hack: https://gist.github.
by rcarmo 9y ago
This is great, but it's sobering to see how hard it is to get a nice, "complete" PDF screenshot out of a modern site.
Here's a quick hack: https://gist.github.com/rcarmo/cf698b52832d0ec356c147cf9c9ad898 https://gist.github.com/rcarmo/cf698b52832d0ec356c147cf9c9ad...
I'm using The Verge for testing because it lazy loads images, and am being clumsy about the scrolling, but it mostly works - I can get 90% of the images to show on the finished PDF.
What I can't seem to get right, though, is creating a single-page PDF where the page height matches the document height perfectly - it always seems to be off by a bit, at least on this site (mine works fine, _sometimes_).
Anyone got an idea of why this is so?
- Ded7xSEoPKYNsDd 9y agoIf I'm reading [1] right, you want to use getBoundingClientRect() instead of clientHeight, which does not account for borders and margins. 1: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_...
- rcarmo 9y agoWell, no, really. Seems like this is due to the way Chrome deals with print CSS and PDF generation rather than any kind of calculations I do prior to invoking PDF generation...