First off, you can probably just create the pdf before it loads, since wkhtmltopdf can process and execute javascript. You may need to adjust the :javascript_delay
setting if it isn't completely finishing running the JS.
Otherwise, you may want to package up the html in #content#
, and send it as a param to a PDF-creating endpoint, with something like this:
$(function(){
form = $('<form action="/pages/report.pdf"><input id="form_content" name="form_content"></form>');
html_content = $('#content').html();
$('#form_content').val(html_content);
form.submit();
});
And an endpoint something like this:
format.pdf do
@content = params[:form_content]
render :pdf => 'report.pdf'
end
and a view that uses @content:
<%= @content %>
This endpoint probably should not do double duty with an html view, since that injected content could open you up to CSRF or XSS issues.