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

标签 html node.js pdf phantomjs

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

最佳答案

为什么不使用 html-pdf使用 phantomJS 的 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' } 
});

关于html - 如何在 node.JS 中使用 phantomJs 将 html 内容呈现为 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37223714/

相关文章:

Javascript正则表达式所有匹配

pdf - 页面旋转以何种方式影响 PDF 中的给定表单字段?

php - 是否有与 TCPDF 的 'annotate' 函数等效的 python ReportLab?

java - 创建的itext、pdf无法打开

android - Html.fromHtml 不适用于跨度

javascript - 使用 javascript 困难生成 html

html - div 在 div 中奇怪的空间行为

jquery - FireFox 中使用 jQuery DataTables 时出现样式错误

node.js - MongoDB CursorNotFound 在 collection.find() 上出现数百个小记录错误

node.js - 在 grunt-contrib-connect 中打开任务,在 appName 参数中指定浏览器模式和文档模式