Skip to content

Commit 2e18e88

Browse files
committed
Merge pull request #18 from marcbachmann/phantom-path
Phantom path
2 parents fe94e72 + 187aa2b commit 2e18e88

7 files changed

Lines changed: 54 additions & 32 deletions

File tree

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.1.0
2+
=====
3+
- From now on options.phantomPath allows you to overwrite the default PhantomJS binary path.
4+
5+
16
1.0.0
27
=====
38
- Catch phantomjs errors [517d307](https://github.com/marcbachmann/node-html-pdf/commit/517d30762e3121f72aa3879e07f5944c05c4d96d)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ config = {
8181
"quality": "75", // only used for types png & jpeg
8282

8383
// Script options
84-
"script": '/url' // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
85-
"timeout": 10000 // Timeout that will cancel phantomjs, in milliseconds
84+
"phantomPath": "./node_modules/phantomjs/bin/phantomjs", // PhantomJS binary which should get downloaded automatically
85+
"script": '/url', // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
86+
"timeout": 30000 // Timeout that will cancel phantomjs, in milliseconds
8687

8788
}
8889
```

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pdf.js

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/scripts/pdf_a4_portrait.js

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-pdf",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "HTML to PDF converter that uses phantomjs",
55
"main": "lib/index.js",
66
"directories": {
@@ -16,7 +16,7 @@
1616
"tape": "^3.4.0",
1717
"tap-spec": "^2.2.0"
1818
},
19-
"dependencies": {
19+
"optionalDependencies": {
2020
"phantomjs": "^1.9.8"
2121
},
2222
"repository": {

src/pdf.coffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ Stream = require('stream').Readable
33
childprocess = require('child_process')
44
path = require('path')
55
assert = require('assert')
6-
phantomjs = require('phantomjs')
6+
7+
try
8+
phantomjs = require('phantomjs')
9+
catch err
10+
console.log('html-pdf: Failed to load PhantomJS module.', err)
711

812
#
913
# phantomjs version 1.8.1 and later should work.
@@ -26,6 +30,8 @@ module.exports = class PDF
2630
@script = path.join(__dirname, 'scripts', 'pdf_a4_portrait.js')
2731

2832
@options.filename = path.resolve(@options.filename) if @options.filename
33+
@options.phantomPath ?= phantomjs?.path
34+
assert(@options.phantomPath, "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'")
2935
assert(typeof @html is 'string' && @html.length, "html-pdf: Can't create a pdf without an html string")
3036

3137

@@ -63,7 +69,7 @@ module.exports = class PDF
6369

6470

6571
exec: (callback) ->
66-
child = childprocess.spawn(phantomjs.path, [@script])
72+
child = childprocess.spawn(@options.phantomPath, [@script])
6773
stdout = []
6874
stderr = []
6975

0 commit comments

Comments
 (0)