user453575457
user453575457

Reputation: 602

Why phantom doesn't renders page correctly?

I'm trying to render html to jpg using phantomjs.

Phantom renders stack overflow site perfectly, but doesn't render my own html page (which shows pieChart, generated by js).

here is phantom script:

var webPage = require('webpage');
var system = require('system');
var page = webPage.create();


page.viewportSize = { width: 1920, height: 1080 };
page.open(system.args[1], function start(status) {
  page.render('index.jpeg', {format: 'jpeg', quality: '100'});
  phantom.exit();
});

And here is output img:

enter image description here

How to fix rendering?

Upvotes: 0

Views: 128

Answers (1)

Vaviloff
Vaviloff

Reputation: 16838

The chart is probably not shown in the image because the screenshot is made immediately after page is opened. Try to postpone making a screenshot for a second like this:

page.open(system.args[1], function start(status) {
  setTimeout(function(){
    page.render('index.jpeg', {format: 'jpeg', quality: '100'});
    phantom.exit();
  }, 1000);
});

Upvotes: 1

Related Questions