wicked_pdf image rendering

两盒软妹~` 提交于 2019-12-05 16:27:36

Version 0.7.9 is

<%= wicked_pdf_image_tag 'myfile.jpg' %>

It basically returns the absolute path on the file system:

file:///path/to/image/myfile.jpg

Also see: https://github.com/mileszs/wicked_pdf

ok, so I found the answer

the <%= image_tag(asset.asset.url(:medium)) %> code generates the url to the image that in html will look like <img alt="2012_bmw_7_series_gearshift" src="/system/assets/174/original/2012_bmw_7_series_gearshift.jpg?1318267462"> so my images starts in system map and all I had to do is to write a method in application_helper.rb like this:

module ApplicationHelper

 def pdf_image_tag(image, options = {})
  options[:src] = File.expand_path(RAILS_ROOT) + '/public' + image
  tag(:img, options)
 end
end

this way wiked_pdf will know that image tag called pdf_image_tag will start from system folder in public and the final code for the pdf.html.erb will be:

<% for asset in @car.assets %>
  <%= pdf_image_tag(asset.asset.url(:medium), :style=>"margin:0px;padding:0px", :width=>"250", :height=>"200")%>
<% end %>

was easy, but still took me a few days to figure it out. Nice day.

Instead of using wicked_pdf_image_tag helper it's possible to use image_tag and image_url rails helpers together to get absolute path to image (this is what required for wicked_pdf gem):

image_tag image_url('dir/image.png')

here dir/image.png is image path relative to standard location in rails app (app/assets/images for images).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!