Skip to content

Instantly share code, notes, and snippets.

@jpts
Created November 23, 2016 15:05
Show Gist options
  • Save jpts/c3326feb3a8658f5856126b0e6f03c7a to your computer and use it in GitHub Desktop.
Save jpts/c3326feb3a8658f5856126b0e6f03c7a to your computer and use it in GitHub Desktop.
#!/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