Skip to content

Commit 91b359c

Browse files
committed
Improve renderDelay option and add to README.
1 parent 63a8d28 commit 91b359c

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ config = {
134134
"script": '/url', // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
135135
"timeout": 30000, // Timeout that will cancel phantomjs, in milliseconds
136136

137+
// Time we should wait after window load
138+
// accepted values are 'manual', some delay in milliseconds or undefined to wait for a render event
139+
"renderDelay": 1000,
140+
137141
// HTTP Headers that are used for requests
138142
"httpHeaders": {
139143
// e.g.

lib/scripts/pdf_a4_portrait.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,25 @@ setTimeout(function () {
5353

5454
// Completely load page & end process
5555
// ----------------------------------
56-
page.onLoadFinished = function (status) {
57-
// The paperSize object must be set at once
56+
if (options.renderDelay === 'manual') page.onCallback = renderNow
57+
else if (typeof options.renderDelay === 'number') setTimeout(renderNow, options.renderDelay)
58+
else page.onLoadFinished = renderNow
59+
60+
function renderNow () {
5861
page.paperSize = definePaperSize(getContent(page), options)
5962

60-
// Output to parent process
6163
var fileOptions = {
6264
type: options.type || 'pdf',
6365
quality: options.quality || 75
6466
}
6567

6668
var filename = options.filename || (options.directory || '/tmp') + '/html-pdf-' + system.pid + '.' + fileOptions.type
6769

68-
takeShot();
69-
function takeShot(){
70-
var title = page.evaluate(function() {
71-
return document.title;
72-
});
73-
74-
if(title.toUpperCase() != "DONE" && options.onTitleDone){
75-
window.setTimeout(function () {
76-
takeShot();
77-
}, 400);
78-
} else {
79-
page.render(filename, fileOptions)
80-
phantom.exit();
81-
82-
system.stdout.write(JSON.stringify({filename: filename}))
70+
page.render(filename, fileOptions)
8371

84-
exit(null)
85-
}
86-
}
72+
// Output to parent process
73+
system.stdout.write(JSON.stringify({filename: filename}))
74+
exit(null)
8775
}
8876

8977
// Returns a hash of HTML content

0 commit comments

Comments
 (0)