Skip to content

Instantly share code, notes, and snippets.

@dylandy
Created July 14, 2016 14:00
Show Gist options
  • Save dylandy/7da6875b56e3b7d6a2614b4b2f8e4b68 to your computer and use it in GitHub Desktop.
Save dylandy/7da6875b56e3b7d6a2614b4b2f8e4b68 to your computer and use it in GitHub Desktop.
convert from html to pdf
var fs = require('fs');
var pdf = require('html-pdf');
var args = process.argv;
var htmlfile = args[2];
var pdffile = args[3];
if(htmlfile === undefined || pdffile === undefined) {
console.error('You must supply a html filename, and then a PDF filename.');
process.exit();
}
var html = fs.readFileSync(htmlfile, 'utf8')
var options = { filename: pdffile, format: 'Letter' };
pdf.create(html, options).toFile(function(err, res) {
if (err) return console.log(err);
console.log(res); // { filename: '/tmp/html-pdf-8ymPV.pdf' }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment