Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module api #11

Merged
merged 9 commits into from
Jan 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.11"
23 changes: 0 additions & 23 deletions Gruntfile.coffee

This file was deleted.

46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,46 @@
[Example Receipt](http://public.admintools.ch/gh/html-pdf/order.pdf)


## Example
```javascript
var fs = require('fs');
var pdf = require('./lib');
var pdf = require('html-pdf');
var html = fs.readFileSync('./test/businesscard.html', 'utf8')
pdf.create(html, { width: '50mm', height: '90mm'}, function(err, buffer) {
var options = { filename: './businesscard.pdf', format: 'Letter' };

pdf.create(html, options).toFile(function(err, res) {
if (err) return console.log(err);
fs.writeFile('businesscard.pdf', buffer);
console.log(res); // { filename: '/tmp/html-pdf-8ymPV.pdf' }
});
```

## API
Currently there is only one function
```javascript
var pdf = require('html-pdf');
var callback = function(err, buffer){}
pdf.create(htmlString, options, callback)

```js
pdf.create(html [, options]).toFile([filepath, ]callback)
pdf.create(html [, options]).toBuffer(callback)
pdf.create(html [, options]).toStream(callback)

// for backwards compatibility
pdf.create(html [, options], callback)

```


## Options
```javascript
config = {
// Script options
script: '/url' // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
timeout: 10000 // Timeout that will cancel phantomjs, in milliseconds

// Export options
"directory": "/tmp" // The directory the file gets written into if not using .toFile(filename, callback). default: '/tmp'

// Papersize Options: http://phantomjs.org/api/webpage/property/paper-size.html
"height": "", // allowed units: mm, cm, in, px
"width": "", // allowed units: mm, cm, in, px
"height": "10.5in", // allowed units: mm, cm, in, px
"width": "8in", // allowed units: mm, cm, in, px
- or -
"format": "A4", // allowed units: A3, A4, A5, Legal, Letter, Tabloid
"format": "Letter", // allowed units: A3, A4, A5, Legal, Letter, Tabloid
"orientation": "portrait", // portrait or landscape


// Page options
"border": "0" // default is 0, units: mm, cm, in, px
"header": {
Expand All @@ -50,18 +57,15 @@ config = {
"height": "28mm",
"contents": '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>'
},


// File options
"type": "pdf", // allowed file types: png, jpeg, pdf
"quality": "75", // only used for types png & jpeg

// Script options
"script": '/url' // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
"timeout": 10000 // Timeout that will cancel phantomjs, in milliseconds

// Export options
"buffer": true, // only supported on certain systems
- or -
"filename": "/tmp/html-pdf-123-123.pdf" // The file path of the file that will be written. If you want to save the file permanently, you have to pass this option.
"directory": "/tmp" // The directory the file gets written into if no filename is defined. default: '/tmp'
}
```

Expand Down
2 changes: 0 additions & 2 deletions index.js

This file was deleted.

72 changes: 0 additions & 72 deletions lib/index.coffee

This file was deleted.

86 changes: 22 additions & 64 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading