phantom-html-to-pdf
phantom-html-to-pdf copied to clipboard
add workaround changing zoom on linux
The pdf generated on linux and windows looks differently. The issue is described here. I have tried the proposed workaround and it is partially working. The output pdf files are still a little bit different, but it is not that significant.
This result is the most far I got: linux.pdf windows.pdf
I guess this should be an optional behavior user can opt in. However we should for sure recommend the users to design pdf files on the same platform where the production will run.
I guess this should be an optional behavior user can opt in.
i think the same too
However we should for sure recommend the users to design pdf files on the same platform where the production will run.
for teams with multiple OS this will be a huge pain (like my team) :(, not cool but i guess this is the best that we can do for now
with phantom 1.9.8 the problem/inconsistency seems to be only in windows, so we should normalize windows not linux/osx .. there are other solutions as described in this thread, will try to dive into it more and try more solutions.
Hmm. Maybe better do this at once with upgrade to 2.0. Otherwise we could be fixing this twice.
@pofider seems reasonable.. leave the issue open in case someone explore the problem a little more or find others workarounds :)
The fix works, but only sort of. The 0.654545
value was no good for me. Had to set it to 0.5625
on linux and 0.75
on windows.
(0.75^2 = 0.5625)
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
page.evaluate(function() {
document.body.style["transform-origin"] = "0 0";
document.body.style["-webkit-transform-origin"] = "0 0";
document.body.style["transform"] = "scale(0.555)";
document.body.style["-webkit-transform"] = "scale(0.555)";
});
window.setTimeout(function () {
page.render(output, { format: format });
phantom.exit(0);
}, 200);
}
});
and 0.75 on windows.
i can confirm that the correct value on unix OS is 0.5625
(but probably this won't work on all cases, better to test more reports and see how it goes..)
the workaround is only for unix (linux, osx), windows is a reference for the others OS.
what works on windows with zoom = 1.0, works on unix with zoom = 0.5625.
like i said before i think this patch should be applied in user-land, better for us to wait for phantom 2.0 (it still have issues for pdf rendering)
I've tested this both on windows and mac and can confirm the values above for zoom do fix highchart image sizes but has no effect on the text. On windows the text is still a lot smaller. I set the zoom when I call rasterize.js.
Is there a workaround to getting both the images and text to be consistent on both platforms?