In generating PDFs in Phantom, I can set the paper size like this:
page.paperSize = {
height: '8.5in',
width: '11in',
orientation: 'landscape',
border: '0.4in'
};
then the page.render(output) function generates a PDF properly. In other words, the size is correct and it has many pages of that size.
I can't get this to work in Casper (and I'm not sure if it is supported). So for example, the following:
var casper = require('casper').create({
paperSize: {
height: '8.5in',
width: '11in',
orientation: 'landscape',
border: '0.4in'
},
logLevel: 'debug',
verbose: true
});
....this.capture('print.pdf'); ...
creates a PDF with a single, very long page. Setting viewportSize does not fix the problem.
Is there any way to access the pageSize object from within Casperjs?
You can access paperSize through casper.page.paperSize, however you will need to set this after calling casper.start(), otherwise casper.page will be equal to null.
Here's an example:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With