在用幻影生成PDF时,我可以像这样设置纸张大小:
page.paperSize = {
height: '8.5in',
width: '11in',
orientation: 'landscape',
border: '0.4in'
};然后,page.render(output)函数正确地生成一个PDF。换句话说,大小是正确的,而且它有很多这样的页面。
我无法让它在Casper中工作(我不确定它是否被支持)。例如,以下内容:
var casper = require('casper').create({
paperSize: {
height: '8.5in',
width: '11in',
orientation: 'landscape',
border: '0.4in'
},
logLevel: 'debug',
verbose: true
});
....this.capture('print.pdf'); ...用一个非常长的页面创建一个PDF。设置viewportSize不能解决问题。
有任何方法从Casperjs内部访问pageSize对象吗?
发布于 2013-05-18 21:40:14
您可以通过paperSize访问casper.page.paperSize,但是您需要在调用casper.start()之后设置它,否则casper.page将等于null。
下面是一个例子:
var casper = require("casper").create();
casper.start();
casper.page.paperSize = {
width: '11in',
height: '8.5in',
orientation: 'landscape',
border: '0.4in'
};
casper.thenOpen('http://www.facebook.com/', function() {
this.capture('test.pdf');
this.echo('created pdf.');
});
casper.run();https://stackoverflow.com/questions/16628737
复制相似问题