I am using the wicked_pdf gem to generate a PDF of an invoice, which has a logo image. When I use the Rails helper:
<%= image_tag('logo.svg'), alt: "alternate_text") %>
the logo shows in the browser, but doesn't show when I go to download it.
I saw that the image path needs to be an absolute URL. So I embedded the logo from an external URL: http://path_to_external_url.com/assets/logo.svg (which is an existing Rails application), which works and shows on the downloaded PDF.
I further created a helper in my Rails app to find the root URL of the project as so:
def asset_url(asset)
"#{request.protocol}#{request.host_with_port}#{asset_path(asset)}"
end
then in my view called the helper method:
<%= image_tag(asset_url('logo.svg'), alt: "Meetupcall") %>
Now everything works fine, I can see the image in the browser, but when I click the button to download it, it hangs. I can't understand the reason why it works with a hard-coded URL but not when I use the built in image_tag helper.
I'm using OS X Mountain Lion 10.8.4 and wkhtmltopdf 0.8.3.
This is a copy of the error in the log file:
RuntimeError - Failed to execute: "/Users/Azz/.gem/ruby/2.0.0/bin/wkhtmltopdf" -q "file:////var/folders/ms/b15k263952g5_14lnsgn9gq80000gn/T/wicked_pdf20130715-670-103zzi7.html" "/var/folders/ms/b15k263952g5_14lnsgn9gq80000gn/T/wicked_pdf_generated_file20130715-670-5xs1jt.pdf" Error: PDF could not be generated! Command Error: /Users/Azz/.gem/ruby/2.0.0/gems/wkhtmltopdf-binary-0.9.9.1/bin/wkhtmltopdf:14:in system: Interrupt from /Users/Azz/.gem/ruby/2.0.0/gems/wkhtmltopdf-binary-0.9.9.1/bin/wkhtmltopdf:14:in from /Users/Azz/.gem/ruby/2.0.0/bin/wkhtmltopdf:23:in load from /Users/Azz/.gem/ruby/2.0.0/bin/wkhtmltopdf:23:in main
I've also got this in my gemfile:
gem 'wkhtmltopdf-binary'
gem "wicked_pdf", "~> 0.9.6"