PhantomJs `page.set` 不是函数?
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 })
});
});
});
});
我的代码如上所示,我正在尝试将 pdf
划分到不同的分区中。我收到如下错误。
(node:26328) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: page.set is not a function
我测试了以下两个版本
phantomJs: 1.9.8
phantomJs: 2.1.1
如果有任何其他解决方案,欢迎使用,因为目前,长 HTML 页仅生成单页 PDF。
经过一些研究和阅读深入的文档,我找到了自己的方法。
page.set('paperSize', {format: 'A4', orientation: 'portrait'});
set 在此处已弃用。使用 property
而不是 set
.
page.property('paperSize', {format: 'A4', orientation: 'portrait'});
谢谢
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 })
});
});
});
});
我的代码如上所示,我正在尝试将 pdf
划分到不同的分区中。我收到如下错误。
(node:26328) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: page.set is not a function
我测试了以下两个版本
phantomJs: 1.9.8
phantomJs: 2.1.1
如果有任何其他解决方案,欢迎使用,因为目前,长 HTML 页仅生成单页 PDF。
经过一些研究和阅读深入的文档,我找到了自己的方法。
page.set('paperSize', {format: 'A4', orientation: 'portrait'});
set 在此处已弃用。使用 property
而不是 set
.
page.property('paperSize', {format: 'A4', orientation: 'portrait'});
谢谢