1 | #!/usr/bin/env node
|
2 |
|
3 | var fs = require('fs')
|
4 | var pdf = require('../')
|
5 | var path = require('path')
|
6 |
|
7 | var args = process.argv.slice(2)
|
8 |
|
9 | if (args.length >= 2) {
|
10 | htmlpdf(args[0], args[1])
|
11 | } else {
|
12 | help()
|
13 | }
|
14 |
|
15 | function 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 |
|
24 | function 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 | }
|