diff --git a/lib/index.js b/lib/index.js index dcf3443..2572189 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.9.1 +// Generated by CoffeeScript 1.9.3 (function() { var PDF; diff --git a/lib/pdf.js b/lib/pdf.js index 0f4930e..18eedee 100644 --- a/lib/pdf.js +++ b/lib/pdf.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.9.1 +// Generated by CoffeeScript 1.9.3 (function() { var PDF, Stream, assert, childprocess, err, fs, path, phantomjs; @@ -37,6 +37,7 @@ } assert(this.options.phantomPath, "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'"); assert(typeof this.html === 'string' && this.html.length, "html-pdf: Can't create a pdf without an html string"); + this.options.timeout = parseInt(this.options.timeout) || 30000; } PDF.prototype.toBuffer = function(callback) { @@ -103,7 +104,7 @@ if (!stderr.length) { return stderr = [new Buffer('html-pdf: PDF generation timeout. Phantom.js script did not exit.')]; } - }, parseInt(this.options.timeout) || 30000); + }, this.options.timeout); child.stdout.on('data', function(buffer) { return stdout.push(buffer); }); diff --git a/lib/scripts/pdf_a4_portrait.js b/lib/scripts/pdf_a4_portrait.js index 58c57a3..6795633 100644 --- a/lib/scripts/pdf_a4_portrait.js +++ b/lib/scripts/pdf_a4_portrait.js @@ -1,6 +1,6 @@ -// Generated by CoffeeScript 1.9.1 +// Generated by CoffeeScript 1.9.3 (function() { - var buildStack, content, exit, i, json, len, options, page, paper, ref, ref1, ref2, ref3, setContent, system, totalPages, type, vp, webpage; + var buildStack, content, exit, i, json, len, options, page, paper, ref, ref1, ref2, ref3, setContent, system, timeout, totalPages, type, vp, webpage; system = require('system'); @@ -33,10 +33,6 @@ return exit(buildStack('Script - ' + msg, trace)); }; - setTimeout(function() { - return exit('Force timeout'); - }, 120000); - json = JSON.parse(system.stdin.readLine()); if (!((ref = json.html) != null ? ref.trim() : void 0)) { @@ -59,6 +55,14 @@ return exit(buildStack('Evaluation - ' + msg, trace)); }; + if (timeout = json.options.timeout) { + timeout = timeout + 2000; + } + + setTimeout(function() { + return exit('Force timeout'); + }, timeout || 12000); + content = page.evaluate(function() { var $body, $footer, $header, body, footer, header, styles; styles = document.querySelectorAll('link,style'); diff --git a/package.json b/package.json index a9dcf1a..e3a556c 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,7 @@ "type": "git", "url": "git://github.com/marcbachmann/node-html-pdf.git" }, - "keywords": [ - "html", - "pdf", - "phantom", - "phantomjs", - "nodejs" - ], + "keywords": ["html", "pdf", "phantom", "phantomjs", "nodejs"], "bugs": { "url": "/~https://github.com/marcbachmann/node-html-pdf/issues" }, diff --git a/src/pdf.coffee b/src/pdf.coffee index 236c524..a721e1d 100644 --- a/src/pdf.coffee +++ b/src/pdf.coffee @@ -33,6 +33,7 @@ module.exports = class PDF @options.phantomPath ?= phantomjs?.path assert(@options.phantomPath, "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'") assert(typeof @html is 'string' && @html.length, "html-pdf: Can't create a pdf without an html string") + @options.timeout = parseInt(@options.timeout) || 30000 toBuffer: (callback) -> @@ -77,7 +78,7 @@ module.exports = class PDF child.stdin.end() child.kill() stderr = [new Buffer('html-pdf: PDF generation timeout. Phantom.js script did not exit.')] unless stderr.length - , parseInt(@options.timeout) || 30000 + , @options.timeout child.stdout.on 'data', (buffer) -> stdout.push(buffer) diff --git a/src/scripts/pdf_a4_portrait.coffee b/src/scripts/pdf_a4_portrait.coffee index 863604a..ea903c8 100755 --- a/src/scripts/pdf_a4_portrait.coffee +++ b/src/scripts/pdf_a4_portrait.coffee @@ -22,12 +22,6 @@ phantom.onError = (msg, trace) -> exit(buildStack('Script - '+ msg, trace)) -# Force cleanup after 2 minutes -setTimeout -> - exit('Force timeout') -, 120000 - - # Load configurations from stdin json = JSON.parse(system.stdin.readLine()) exit('Did not receive any html') if !json.html?.trim() @@ -43,6 +37,13 @@ page.onError = (msg, trace) -> exit(buildStack('Evaluation - '+ msg, trace)) +# Force cleanup after 2 minutes +timeout = timeout+2000 if timeout = json.options.timeout +setTimeout -> + exit('Force timeout') +, timeout || 12000 + + # Set up content # -------------- content = page.evaluate ->