简体   繁体   English

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

[英]How can I render html content as pdf file using phantomJs in node.JS

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

Why not use the html-pdf npm module which uses phantomJS? 为什么不使用使用phantomJS的html-pdf npm模块?

Code example 代码示例

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' } 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM