Saturday, 15 August 2015

screen capture - Strange getting width of page in phantomjs -



screen capture - Strange getting width of page in phantomjs -

here script code:

var page = require('webpage').create(); page.papersize = { format: 'a4', orientation: "landscape" }; page.open('http://www.google.com', function () { var arr = page.evaluate(function () { var pagewidth = document.body.clientwidth; var pageheight = document.body.clientheight; homecoming [pagewidth, pageheight]; }); console.log('pagwwidth: ' + arr[0] + '; pageheight: ' + arr[1]); page.render('google.pdf'); phantom.exit(); });

i'm trying clientwidth , clientheight of document.body page. when exec script i'm getting folowing values:

pagwwidth: 400; pageheight: 484

why width above 400px? think should wider.

thank reply. don't understand next thing. when utilize viewportsize = {width: 1024, height: 800}

var page = require('webpage').create(); page.papersize = { format: 'a4', orientation: "landscape" }; page.viewportsize = {width: 1024, height: 800}; page.open('http://www.google.com', function () { page.render('google.pdf'); phantom.exit(); });

i next file:

but if utilize viewportsize = {width: 400, height: 400}

var page = require('webpage').create(); page.papersize = { format: 'a4', orientation: "landscape" }; page.viewportsize = {width: 400, height: 400}; page.open('http://www.google.com', function () { page.render('google.pdf'); phantom.exit(); });

i same:

so don't understand how viewportsize impact view?

the document affected viewport size , not paper size. think along line, how web page looks in web browser has nil current printer setting.

use viewportsize if want influence page layout:

page.viewportsize = { width: 1024, height: 800 };

phantomjs screen-capture

No comments:

Post a Comment