Node.js正在调用一个Phantomjs脚本,该脚本正在加载HTML内容并呈现html和css。一切都在浏览器中工作,但是当脚本生成PDF时,图像不会显示在PDF中。
PhantomJS
var webPage = require('webpage');
var path = require('path');
var page = webPage.create();
var system = require('system'),
filename = system.args[1],
content = system.args[2];
page.viewportSize = { width: 1920, height: 1080 };
page.paperSize = {
format: 'A4',
orientation: 'portrait',
margin: '1cm'
}
page.content = content;
page.onLoadFinished = function() {
page.render('/my/domain/upload/'+filename+".pdf");
phantom.exit();
}
Node.js的
var childProcess = require('child_process'),
phantomjs = require('phantomjs'),
binPath = phantomjs.path,
path = require('path');
console.log(name);
var childArgs = [
path.join(__dirname, 'pdfrender.js'),
name,
html
]
return Q.all([childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
console.log(err);
console.log(stderr);
return Q(err);
})]);
在渲染pdf之前,脚本似乎没有加载图像,或者渲染忽略了图像标记。