Created
July 14, 2016 14:00
-
-
Save dylandy/7da6875b56e3b7d6a2614b4b2f8e4b68 to your computer and use it in GitHub Desktop.
convert from html to pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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