Gunjan Patel
Gunjan Patel

Reputation: 2372

PhantomJs `page.set` is not a function?

var phantom = require('phantom');   //version:"^4.0.12"
phantom.create().then(function(ph) {
    ph.createPage().then(function(page) {
        //page.set('paperSize', {format: 'A4', orientation: 'portrait'});
        page.open("URL").then(function(status) {
            console.log('Status: ' + status);
            page.set('paperSize', {format: 'A4', orientation: 'portrait'});
            page.render('abc.pdf').then(function(response, err) {
                ph.exit();
                if (err) return res.status(400).send({ status: false, message: JSON.stringify(err) })
                return res.status(200).send({ status: true, message: response })
            });
        });
    });
});

My code is looking like above, I'm trying to divide pdf in a different partition. I got an error like follow.

(node:26328) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: page.set is not a function

I tested with following both versions

phantomJs: 1.9.8 phantomJs: 2.1.1

If any other solution than welcome because currently, only single page PDF generated for long HTML page.

Upvotes: 0

Views: 451

Answers (1)

Gunjan Patel
Gunjan Patel

Reputation: 2372

I found my own ways after some research and reading deep documentation.

page.set('paperSize', {format: 'A4', orientation: 'portrait'});

set is deprecated over here. Use property instead of set.

page.property('paperSize', {format: 'A4', orientation: 'portrait'});

Thanks

Upvotes: 2

Related Questions