score:1

Accepted answer

There is a Fork with a fix for that. You can set the dpi now with this fork: https://github.com/martonw/phantomjs/tree/issue-%2313553

You need to compile it for your OS and then you can set the dpi with page.dpi

console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://phantomjs.org/';
   page.open(url, function (status) {
   //Page is loaded!
   page.dpi=300; // this is where you actually set the DPI
   page.render("test.pdf");
   phantom.exit();
}

Be sure you use the same OS for phatomjs on where you compile it, because the compile process reads the dpi from the system and uses it for phantomjs. This means: If you compile it on windows with standard dpi 96 and use it on centos you will have a scale of 96/72 because centos uses 72 dpi

score:0

Yes, >2.0 has a poorly defined A4. I scale my html by adjusting the css style from within rasterize.js just before the .render command.

page.evaluate(function () {
    var the_page = document.getElementsByTagName("page")[0];
    the_page.style.transformOrigin='0 0';
    the_page.style.WebkitTransformOrigin='0 0';
    the_page.style.transform='scale(1.28)';
    the_page.style.webkitTransform ='scale(1.28)';
);

Related Query

More Query from same tag