UNPKG

623 BJavaScriptView Raw
1#!/usr/bin/env node
2
3var fs = require('fs')
4var pdf = require('../')
5var path = require('path')
6
7var args = process.argv.slice(2)
8
9if (args.length >= 2) {
10 htmlpdf(args[0], args[1])
11} else {
12 help()
13}
14
15function help () {
16 var help = [
17 'Usage: html-pdf <source> <destination>',
18 'e.g.: html-pdf source.html destination.pdf'
19 ].join('\n')
20
21 console.log(help)
22}
23
24function htmlpdf (source, destination) {
25 var html = fs.readFileSync(source, 'utf8')
26 var options = {
27 base: 'file://' + path.resolve(source)
28 }
29 pdf.create(html, options).toFile(destination, function (err, res) {
30 if (err) throw err
31 })
32}