Created
November 23, 2016 15:05
-
-
Save jpts/c3326feb3a8658f5856126b0e6f03c7a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
var fs = require('fs') | |
var pdf = require('../') | |
var path = require('path') | |
var args = process.argv.slice(2) | |
if (args.length >= 2) { | |
htmlpdf(args[0], args[1]) | |
} else { | |
help() | |
} | |
function help () { | |
var help = [ | |
'Usage: html-pdf <source> <destination>', | |
'e.g.: html-pdf source.html destination.pdf' | |
].join('\n') | |
console.log(help) | |
} | |
function htmlpdf (source, destination) { | |
var html = fs.readFileSync(source, 'utf8') | |
var options = { | |
base: 'file://' + path.resolve(source), | |
format: 'A3', | |
border: '2cm' | |
} | |
pdf.create(html, options).toFile(destination, function (err, res) { | |
if (err) throw err | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment