I'm trying to render a PDF of my page that contains a google map but it always comes out as empty. Strange thing is when I call the url using the wkhtmltopdf binary it actually work. Could I be missing something??? Here's my current setup
Home Controller
class HomeController < ApplicationController
def index
respond_to do |format|
format.html
format.pdf do
render pdf: "Example PDF",
layout: 'pdf.html.erb',
show_as_html: params.key?('debug'),
javascript_delay: 3000
end
end
end
end
index.pdf.erb
<%- content_for :js do %>
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src = "//maps.googleapis.com/maps/api/js?&key=GOOGLE_API_KEY"></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
$(window).load(function(){
initMap();
})
</script>
<% end %>
<h1>Google Map</h1>
<div id="map" style="width: 800px; height: 400px;"></div>
With debug set to true (to see the html that is used to render the pdf)

When I load the pdf url the map section is not rendered

When I used the wkhtmltopdf command line utitlity. It correctly renders the pdf.
$ wkhtmltopdf --javascript-delay 3000 http://localhost:4000/home/index.pdf?debug output.pdf
Is there anything i'm doing wrong inside the rails app?? Some pointers would really help. Thank you!

wkhtmltopdfinstalled and are executing a different version on the terminal. This could be the case if you have: rubygems.org/gems/wkhtmltopdf-binary. Look at the command executed in the rails logs for more details, and try replicating that command exactly in the terminal. - Brendon Muir"***[\"/usr/local/bin/wkhtmltopdf\", \"-q\", \"--javascript-delay\", \"3000\", \"file:////var/folders/y4/18x7npks3w5b_yr8jz304wzr0000gn/T/wicked_pdf20180723-2048-1h1m8w7.html\", \"/var/folders/y4/18x7npks3w5b_yr8jz304wzr0000gn/T/wicked_pdf_generated_file20180723-2048-u71ska.pdf\"]*****"and doingwhich wkhtmltopdfreturns/usr/local/bin/wkhtmltopdfwhich is the exact binary being used. Everything looks to be as it should - Joseph N.