Add image in pdf using Prawn

China☆狼群 提交于 2019-12-21 03:43:17

问题


I've a problem for adding images into a PDF using Prawn as pdf generator. I'm trying to add image using the following code:

def header
  text "something"
  image "#{Prawn::DATADIR}/images/logo_small.png"
end

But app replies to me with the following error:

 uninitialized constant Prawn::DATADIR

Where is the mistake?

P.S. My app is running on Rails 3.1 & Ruby 1.9.2.


回答1:


Prawn::DATADIR is new, it has been introduced recently about 2 or 3 months ago. Previously one would have used Prawn::BASEDIR/data instead. If you are using the current 0.12.0 version of the gem, you should stick with Prawn::BASEDIR/data. If you are using Rails 3.1, you can also put your image in the asset directory and use "#{Rails.root}/app/assets/images/logo_small.png"



来源:https://stackoverflow.com/questions/9565412/add-image-in-pdf-using-prawn

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