Skip to content

Commit 12aa074

Browse files
committed
Wait for page load in phantomjs script
1 parent 613840d commit 12aa074

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

lib/scripts/pdf_a4_portrait.coffee

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,23 @@ else
5656

5757
page.paperSize = paperSize
5858

59+
page.onLoadFinished = (status) ->
60+
# Output to parent process
61+
fileOptions =
62+
type: options.type || 'pdf'
63+
quality: options.quality || 75
5964

65+
# Option 1: Output file to stdout
66+
# Not working in Ubuntu 12.04 (at least not in my environment)
67+
if options.buffer
68+
page.render('/dev/stdout', fileOptions)
6069

61-
# Output to parent process
62-
fileOptions =
63-
type: options.type || 'pdf'
64-
quality: options.quality || 75
6570

66-
# Option 1: Output file to stdout
67-
# Not working in Ubuntu 12.04 (at least not in my environment)
68-
if options.buffer
69-
page.render('/dev/stdout', fileOptions)
70-
71-
72-
# Option 2: Output filename to stdout
73-
else
74-
filename = options.filename || ("#{options.directory || '/tmp'}/html-pdf-#{sys.pid}-#{size}.#{fileOptions.type}")
75-
page.render(filename, fileOptions)
76-
sys.stdout.write(filename)
71+
# Option 2: Output filename to stdout
72+
else
73+
filename = options.filename || ("#{options.directory || '/tmp'}/html-pdf-#{sys.pid}-#{size}.#{fileOptions.type}")
74+
page.render(filename, fileOptions)
75+
sys.stdout.write(filename)
7776

7877

79-
phantom.exit(0)
78+
phantom.exit(0)

0 commit comments

Comments
 (0)