I am trying to render a pdf of my model containing images stored with dragonfly using wkhtmltopdf but I can't get it to work. The html page renders fine when I use the debug option for wkhtmltopdf but the pdf itself just gets an empty box where the image should go. So far I've only found two sites where this is brought up (a german blog and a google forum thread), but neither solution solved it for me. My suspicion is that I should use absolute paths to the image files, which is suggested in the blog, but when I try that solution the server gets stuck at:
Rendered images/show.pdf.erb (19.9ms)
"***************[\"/home/oskar/.rbenv/versions/2.2.3/bin/wkhtmltopdf\",
\"-q\", \"--encoding\", \"utf8\", \"--orientation\", \"Landscape\",
\"file:////tmp/wicked_pdf20161007-8095-1nlruhe.html\", \"/tmp
/wicked_pdf_generated_file20161007-8095-1f6vr27.pdf\"]***************"
My code looks like this:
image.rb
class Image < ActiveRecord::Base
dragonfly_accessor :image
end
images_controller.rb:
def show
respond_to do |format|
format.html
format.pdf do
render pdf: 'name',
background: true,
encoding: 'utf8',
orientation: 'Landscape',
:show_as_html => params[:debug].present?
end
end
end
show.pdf.erb:
<% if params[:debug].present? %>
<%= stylesheet_link_tag 'document' %>
<%= stylesheet_link_tag 'pdf' %>
<% else %>
<%= wicked_pdf_stylesheet_link_tag 'document' %>
<%= wicked_pdf_stylesheet_link_tag 'pdf' %>
<% end %>
...
<%= image_tag image.url if image.image_stored? %>
...
image.url = http://localhost:3000/media/W1siZiIsIjYyIl1d/imagename.png
Any advice will be appreciated!
You need to replace
image_tagwithwicked_pdf_image_tag