如何使用node.JS中的phantomJs将html内容呈现为pdf文件

Sya*_*nda 5 html pdf node.js phantomjs

如何使用某些html内容生成pdf文件,并使用node.js中的phantom.js将文件和内容呈现给浏览器?

Tal*_*sar 7

为什么不使用使用phantomJS 的html-pdf npm模块?

代码示例

var fs = require('fs');
var pdf = require('html-pdf');
var html = fs.readFileSync('./test/businesscard.html', 'utf8');
var options = { format: 'Letter' };

pdf.create(html, options).toFile('./businesscard.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/app/businesscard.pdf' } 
});
Run Code Online (Sandbox Code Playgroud)