I'm exporting a webpage of variable height into pdf using PhantomJS. Since pdfs can have any page size (more like ratio though, since it's vectorial), I would like to export it in a way that creates a single page in the pdf in which to fit the entire webpage.
Luckily, using the evaluate
PhantomJS method I can easily detect the page height
page.includeJs('jquery.js', function() {
var pageHeight = page.evaluate(function() {
return $('#content').height();
});
});
However, I'm not sure how I can use that to my advantage. viewportSize
doesn't seem to affect this in any way, since I'm not rendering the viewport but the entire document. I set it to a fixed {width: 800, height: 800}
So I can't wrap my head around the paperSize
sizes. Setting the height to the returned pageHeight will render 1.5x pages, so I tried tweaking the width but it doesn't really add up to any formula that I can understand.
Any ideas in how to achieve this, or do you have more insights into the correlation between the paperSize
property and the pixel-sized bounds rendered from the page