使用 Prawn 在 pdf 中添加图像 [英] Add image in pdf using Prawn

查看:27
本文介绍了使用 Prawn 在 pdf 中添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Prawn 作为 pdf 生成器将图像添加到 PDF 时遇到问题.我正在尝试使用以下代码添加图像:

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

错在哪里?

附言我的应用程序在 Rails 3.1 & 上运行红宝石 1.9.2.

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

推荐答案

Prawn::DATADIR 是新的,最近大约 2 或 3 个月前推出.以前人们会使用 Prawn::BASEDIR/data 代替.如果您使用的是当前 0.12.0 版本的 gem,您应该坚持使用 Prawn::BASEDIR/data.如果您使用的是 Rails 3.1,您还可以将您的图像放在资产目录中并使用"#{Rails.root}/app/assets/images/logo_small.png"

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"

这篇关于使用 Prawn 在 pdf 中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆