Skip to content

Commit

Permalink
added wait before render setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fara committed Dec 11, 2014
1 parent e187c5b commit aa445aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
9 changes: 5 additions & 4 deletions phantom_pdf/generator.py
Expand Up @@ -122,7 +122,7 @@ def _return_response(self, file_src, basename):

def request_to_pdf(self, request, basename,
format=DEFAULT_SETTINGS['PHANTOMJS_FORMAT'],
orientation=DEFAULT_SETTINGS['PHANTOMJS_ORIENTATION']):
orientation=DEFAULT_SETTINGS['PHANTOMJS_ORIENTATION'], wait_before_render=0):
"""Receive request, basename and return a PDF in an HttpResponse."""

file_src = self._set_source_file_name(basename=basename)
Expand Down Expand Up @@ -152,7 +152,8 @@ def request_to_pdf(self, request, basename,
cookie_file,
domain,
format,
orientation
orientation,
wait_before_render
], close_fds=True, stdout=PIPE, stderr=STDOUT)
phandle.communicate()

Expand All @@ -165,7 +166,7 @@ def request_to_pdf(self, request, basename,

def render_to_pdf(request, basename,
format=DEFAULT_SETTINGS['PHANTOMJS_FORMAT'],
orientation=DEFAULT_SETTINGS['PHANTOMJS_ORIENTATION']):
orientation=DEFAULT_SETTINGS['PHANTOMJS_ORIENTATION'], wait_before_render=0):
"""Helper function for rendering a request to pdf.
Arguments:
request = django request.
Expand All @@ -175,5 +176,5 @@ def render_to_pdf(request, basename,
"""
request2pdf = RequestToPDF()
response = request2pdf.request_to_pdf(request, basename, format=format,
orientation=orientation)
orientation=orientation, wait_before_render=wait_before_render)
return response
23 changes: 13 additions & 10 deletions phantom_pdf_bin/generate_pdf.js
Expand Up @@ -19,6 +19,7 @@ cookie_file = system.args[3];
domain = system.args[4];
format = system.args[5]
orientation = system.args[6];
wait_before_render = system.args[7];

info = fs.read(cookie_file).split(' ');
csrftoken = info[0];
Expand All @@ -44,15 +45,17 @@ page.open(address, function (status) {
console.log('Unable to load the address!');
phantom.exit();
} else {
// If we are here, it means we rendered page successfully
// Use "evaluate" method of page object to manipulate the web page
// Notice I am passing the data into the function, so I can use
// them on the page
page.evaluate(function(data) {
}, data);

// Now create the output file and exit PhantomJS
page.render(output);
phantom.exit();
window.setTimeout(function () {
// If we are here, it means we rendered page successfully
// Use "evaluate" method of page object to manipulate the web page
// Notice I am passing the data into the function, so I can use
// them on the page
page.evaluate(function(data) {
}, data);

// Now create the output file and exit PhantomJS
page.render(output);
phantom.exit();
}, wait_before_render);
}
});

0 comments on commit aa445aa

Please sign in to comment.