File tree Expand file tree Collapse file tree 2 files changed +13
-21
lines changed Expand file tree Collapse file tree 2 files changed +13
-21
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,10 @@ config = {
134
134
" script" : ' /url' , // Absolute path to a custom phantomjs script, use the file in lib/scripts as example
135
135
" timeout" : 30000 , // Timeout that will cancel phantomjs, in milliseconds
136
136
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
+
137
141
// HTTP Headers that are used for requests
138
142
" httpHeaders" : {
139
143
// e.g.
Original file line number Diff line number Diff line change @@ -53,37 +53,25 @@ setTimeout(function () {
53
53
54
54
// Completely load page & end process
55
55
// ----------------------------------
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 ( ) {
58
61
page . paperSize = definePaperSize ( getContent ( page ) , options )
59
62
60
- // Output to parent process
61
63
var fileOptions = {
62
64
type : options . type || 'pdf' ,
63
65
quality : options . quality || 75
64
66
}
65
67
66
68
var filename = options . filename || ( options . directory || '/tmp' ) + '/html-pdf-' + system . pid + '.' + fileOptions . type
67
69
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 )
83
71
84
- exit ( null )
85
- }
86
- }
72
+ // Output to parent process
73
+ system . stdout . write ( JSON . stringify ( { filename : filename } ) )
74
+ exit ( null )
87
75
}
88
76
89
77
// Returns a hash of HTML content
You can’t perform that action at this time.
0 commit comments