Skip to content

Commit 21efba5

Browse files
committed
Add phantomPath option
1 parent fe94e72 commit 21efba5

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)