如何在node.js中使用phantomJs将html内容呈现为pdf文件 [英] How can I render html content as pdf file using phantomJs in node.JS

查看:68
本文介绍了如何在node.js中使用phantomJs将html内容呈现为pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I generate a pdf file with some html content and render the file and content to the browser using phantom.js in node.js?

推荐答案

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

Why not use the html-pdf npm module which uses phantomJS?

代码示例

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

这篇关于如何在node.js中使用phantomJs将html内容呈现为pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆