77[ Example Receipt] ( http://public.admintools.ch/gh/html-pdf/order.pdf )
88
99
10+ ## Example
1011``` javascript
1112var fs = require (' fs' );
1213var pdf = require (' html-pdf' );
1314var html = fs .readFileSync (' ./test/businesscard.html' , ' utf8' )
1415var options = { filename: ' ./businesscard.pdf' , format: ' Letter' };
15- pdf (html, options).exec (function (err , res ) {
16+
17+ pdf .create (html, options).toFile (function (err , res ) {
1618 if (err) return console .log (err);
17- console .log (res);
18- /*
19- {
20- filename: './businesscard.pdf',
21- pages: 1
22- }
23- */
19+ console .log (res); // { filename: '/tmp/html-pdf-8ymPV.pdf' }
2420});
2521```
2622
2723## API
24+
2825``` js
29- pdf (html [, options]).toFile (callback)
30- pdf (html [, options]).toBuffer (callback)
31- pdf (html [, options]).toStream (callback)
26+ pdf . create (html [, options]).toFile (callback)
27+ pdf . create (html [, options]).toBuffer (callback)
28+ pdf . create (html [, options]).toStream (callback)
3229
3330// for backward compatibility
3431pdf .create (html [, options], callback)
3532
3633```
3734
3835
39- ``` javascript
40- var pdf = require (' html-pdf' );
41- pdf .create (htmlString, options, function (err , res ){
42- console .log (res); // { "filename": "/tmp/path" }
43- })
44- ```
45-
46-
4736## Options
4837``` javascript
4938config = {
@@ -53,10 +42,10 @@ config = {
5342 " directory" : " /tmp" // The directory the file gets written into if no filename is defined. default: '/tmp'
5443
5544 // Papersize Options: http://phantomjs.org/api/webpage/property/paper-size.html
56- " height" : " " , // allowed units: mm, cm, in, px
57- " width" : " " , // allowed units: mm, cm, in, px
45+ " height" : " 10.5in " , // allowed units: mm, cm, in, px
46+ " width" : " 8in " , // allowed units: mm, cm, in, px
5847 - or -
59- " format" : " A4 " , // allowed units: A3, A4, A5, Legal, Letter, Tabloid
48+ " format" : " Letter " , // allowed units: A3, A4, A5, Legal, Letter, Tabloid
6049 " orientation" : " portrait" , // portrait or landscape
6150
6251 // Page options
@@ -75,8 +64,8 @@ config = {
7564 " quality" : " 75" , // only used for types png & jpeg
7665
7766 // Script options
78- script: ' /url' // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
79- timeout: 10000 // Timeout that will cancel phantomjs, in milliseconds
67+ " script" : ' /url' // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
68+ " timeout" : 10000 // Timeout that will cancel phantomjs, in milliseconds
8069
8170}
8271```
0 commit comments