Reputation: 8723
I am trying to export html to pdf with Phantomjs. Everything is working well, except the size of the html objects in the PDF. There is not effect at all when I use viewportSize or zoomFactor.
var page = require('webpage').create();
page.viewportSize = { width: 800, height: 600};
page.zoomFactor = 2;
page.open("http://www.google.com", function start(status) {
page.render('test.pdf');
phantom.exit();
});
Upvotes: 1
Views: 2384
Reputation: 3807
This tweak can be used to fix this :
Comment below code in rasterize.js
/*if (system.args.length > 4) {
page.zoomFactor = system.args[4];
}
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});*/
Add below code
at the same place.
page.zoomFactor = parseFloat('0.4');
page.open(address, function (status) {
if (status !== 'success') {
phantom.exit(1);
} else {
window.setTimeout(function () {
page.evaluate(function(zoom) {
return document.querySelector('body').style.zoom = zoom;
}, page.zoomFactor);
page.render(output);
phantom.exit();
}, 200);
}
});
Upvotes: 1
Reputation: 8723
This seems to be a known issue in 2.0.0 See https://github.com/ariya/phantomjs/issues/12685
Using PhantomJs Version 1.9.8 works well. See https://gist.github.com/julionc/7476620 for easy installation
Upvotes: 1