mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 645 forks source link

Google Map visualisation #573

Open matthieu80 opened 8 years ago

matthieu80 commented 8 years ago

Hi there, I am creating a pdf with multiple google maps. Each maps are including rich markers and a heat map. While the maps and the rich markers are working fine, the HeatmapLayer does not render. I tried with a javascript delay set to 10 000 ms... The same page renders perfectly well in HTML. I have been turning in circle for hours, any idea is welcome :)

<%= wicked_pdf_stylesheet_link_tag "css_file_name" %>
<%= wicked_pdf_javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
<%= wicked_pdf_javascript_include_tag 'https://maps.google.com/maps/api/js?key=xxxxxxxx&sensor=false&libraries=visualization' %>
unixmonkey commented 8 years ago

This might help:

window_status: 'done_with_heatmap'

which waits to render through wkhtmltopdf until some JS sets window.status to the given string, so you could trigger that with something like this:

// setup_heatmapstuff.then(function() {
  window.status = 'done_with_heatmap';
});

You might also be able to use no_stop_slow_scripts: true.

Also, bear in mind that some of these options are exclusive of others, so adding all 3 strategies probably won't work.

Let me know how it goes!

matthieu80 commented 8 years ago

thank you for your answer! Here is my original code in the controller:

respond_to do |format|
    format.html
    format.pdf do
    render :pdf         => "file_name",
        :save_to_file => Rails.root.join("file.pdf"),
        :layout      => "/layouts/print_layout.html.erb",
        :javascript_delay => 10000
   end
end

The other solutions do not work

'done_with_heatmap' strategy gives the same result (maps are displayed with rich marker, but no heatmap)

controller:

respond_to do |format|
    format.html
    format.pdf do
        render :pdf         => "file_name",
            :save_to_file => Rails.root.join("file.pdf"),
            :layout      => "/layouts/print_layout.html.erb",
            :window_status => 'done_with_heatmap'
    end
end

no_stop_slow_scripts: true Strategy

respond_to do |format|
    format.html
    format.pdf do
        render :pdf         => "file_name",
            :save_to_file => Rails.root.join("file.pdf"),
            :layout      => "/layouts/print_layout.html.erb",
            :no_stop_slow_scripts => true
    end
end

this throws an error:

Error: Failed to execute: ["/Users/matthieuvigneron/.rbenv/versions/2.2.2/bin/wkhtmltopdf", "-q", "--no-stop-slow-scripts", "true", "file:////var/folders/1h/kqzm7y_x77nf7s113d3zcqmw0000gn/T/wicked_pdf20160914-21836-n0k8cc.html", "/var/folders/1h/kqzm7y_x77nf7s113d3zcqmw0000gn/T/wicked_pdf_generated_file20160914-21836-1y17nie.pdf"] Error: PDF could not be generated! Command Error: Error: Failed loading page http://true (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1 due to network error: HostNotFoundError

Also, my Gemfile looks like that (without wkhtmltopdf-binary-edge maps are not displayed):

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'

I might just do something wrong, cannot see it though...

unixmonkey commented 8 years ago

Can you provide a sample html or Rails view file that I can reproduce the issue with?

hitchcockwill commented 7 years ago

@matthieu80 did you find a solution for this issue? I'm facing a very similar problem right now.

samgville commented 6 years ago

Hello! Did anyone find a solution for this yet? @hitchcockwill @matthieu80 , I'm facing a similar problem with jvectormap and a map I need to show on the PDF. I've tried to use the slow generation and adding the js as assets in the app/assets folder but the map is still not showing.