备忘 nodejs生产pdf 组件 node-wkhtmltopdf

备忘 nodejs生产pdf 组件 node-wkhtmltopdf

A Node.js wrapper for the wkhtmltopdf command line tool. As the name implies, it converts HTML documents to PDFs using WebKit.

将Html 转换成PDF


下载地址
https://github.com/devongovett/node-wkhtmltopdf
http://wkhtmltopdf.org/index.html

第一步,下载安装wkhtmltopdf 支持

第二部 , 安装 npm install wkhtmltopdf


调用

var wkhtmltopdf = require('wkhtmltopdf');
var fs = require("fs");

// URL
wkhtmltopdf('http://huqiji.iteye.com/', { pageSize: 'letter' })
  .pipe(fs.createWriteStream('out.pdf'));

// HTML
wkhtmltopdf('<h1>Test</h1><p>Hello world</p>')
  .pipe(res);

// output to a file directly
wkhtmltopdf('http://huqiji.iteye.com/', { output: 'out.pdf' });

// Optional callback
wkhtmltopdf('http://huqiji.iteye.com/', { pageSize: 'letter' }, function (code, signal) {
});
wkhtmltopdf('http://huqiji.iteye.com/', function (code, signal) {
});

你可能感兴趣的:(JavaScript)