Skip to content

Commit e8ed366

Browse files
committed
Very simple CLI
1 parent 3aec6df commit e8ed366

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@
66

77
[Example Receipt](http://public.admintools.ch/gh/html-pdf/order.pdf)
88

9+
## Installation
910

10-
## Example
11+
Install the html-pdf utility via [npm](http://npmjs.org/):
12+
13+
```
14+
$ npm install -g html-pdf
15+
```
16+
17+
## Command-line example
18+
19+
```
20+
$ htmlpdf test/businesscard.html businesscard.pdf
21+
```
22+
23+
## Code example
1124
```javascript
1225
var fs = require('fs');
1326
var pdf = require('html-pdf');

cli/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
var fs = require('fs');
4+
var pdf = require('../');
5+
6+
var args = process.argv.slice(2);
7+
8+
if (args.length >= 2) {
9+
htmlpdf(args[0], args[1]);
10+
} else {
11+
help();
12+
}
13+
14+
function help() {
15+
var help = 'Usage: htmlpdf input.html output.pdf';
16+
console.log(help);
17+
}
18+
19+
function htmlpdf(input, output) {
20+
var html = fs.readFileSync(input, 'utf8');
21+
22+
pdf.create(html).toFile(output, function (err, res) {
23+
if (err) return console.log(err);
24+
});
25+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"directories": {
77
"test": "test"
88
},
9+
"bin": {
10+
"htmlpdf": "cli/index.js"
11+
},
912
"scripts": {
1013
"test": "coffee --compile --output lib/ src/ && coffee test/index.coffee -n"
1114
},

0 commit comments

Comments
 (0)