Phantomjs: Configurable DPI support for PDF rendering

Created on 3 Sep 2015  路  19Comments  路  Source: ariya/phantomjs

it should be possible to set the dpi of the page before calling page.render("example.pdf").

Need code

Most helpful comment

It's not on the 2.1.1, it was added March 2016, see this commit:
https://github.com/ariya/phantomjs/commit/5232c9dff98115600d1b1491e538e01c0de2d650

The 2.1.1 is ancient, it's from Jan 2016.

We should push for a release instead. This is much needed feature.

All 19 comments

The following test script shows the usage and tests the feature:

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();

attached a screenshot how the output looks like.
out

This would indeed be a useful feature, but the development team is swamped at the moment and is unlikely to get to it anytime soon. If you want to work up a patch, though, we'd take it.

Hi @zackw it is done already, along with a pull request, see this commit on this fork I made: https://github.com/martonw/phantomjs/commit/4d11bef6c082a4f8a360953257c54b5090a3e226.

+1 @martonw thank you. it worked for me.

Might be related to #12685.

is there an update on this?

+1

+1

Hasn't this been fixed with #14085?

Landed in master some time ago.

page.dpi = 300; works like a charm 馃憤

Is there a way to make this work using page.setContent instead of page.open? My use case is rendering a pdf from known html, and I would like higher dpi than the default 72

This doesn't seem to work with 2.1.1, it's always small if I use page.dpi = 100; or page.dpi = 600; or page.dpi = 6000; was it moved somewhere?

I got 2.1.1 too (from binary release/linux 64) and it's not working

It's not on the 2.1.1, it was added March 2016, see this commit:
https://github.com/ariya/phantomjs/commit/5232c9dff98115600d1b1491e538e01c0de2d650

The 2.1.1 is ancient, it's from Jan 2016.

We should push for a release instead. This is much needed feature.

@ciantic I agree, we need a 2.1.2... waiting for an hypothetic 2.5 is not a solution

I'm having this issue with Windows 10 auto-scaling. 2 machines will render two completely different PDF in terms of scaling. If the fix is already done and it's pending release, when should we expect it to drop?

Anyone knows where to get a build of this?

I need this as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julmot picture julmot  路  5Comments

mdominado picture mdominado  路  3Comments

mz3 picture mz3  路  5Comments

yisibl picture yisibl  路  5Comments

machadolab picture machadolab  路  5Comments