使用 Prawn 在表中插入图像时出错

发布于 2024-12-15 01:44:50 字数 418 浏览 2 评论 0原文

我正在与 Prawn 一起生成 pdf,我必须在表格的单元格中插入图像。

我的代码是这样的:

image = "path to file"

subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"],
           [formative_1,sumative, {:image => image}]
          ]
table subject 

但是,我收到一条错误消息:

 prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError)

我该如何解决这个问题?非常感谢任何帮助。

干杯!

I am working with Prawn to generate a pdf, I have to insert an image in a cell of a table.

My code is like this:

image = "path to file"

subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"],
           [formative_1,sumative, {:image => image}]
          ]
table subject 

But, I get an error which says:

 prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError)

How can I resolve this? Any help is greatly appreciated.

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我老 2024-12-22 01:44:50

在当前版本的 Prawn 0.12.0 中,无法在 Prawn::Table 中嵌入图像,但此功能似乎正在开发中,请参阅 此处。目前你必须编写自己的表格,例如

data = [[{:image => "red.png"},{:text => "Red"}],
        [{:image => "blue.png"},{:text => "Blue"}]]
data.each_with_index do |row,i|
  row.each_with_index do |cell,j|
    bounding_box [x_pos,y_pos], :width => cell_width, :height => cell_height do
      image(cell[:image], ...) if cell[:image].present?
      text_box(cell[:text], ...) if cell[:text].present?
    end
    x_pos = (x_pos + cell_width)
  end
  y_pos = (y_pos - cell_height)
end

In the current version of Prawn 0.12.0 it is not possible to embed images in a Prawn::Table, but this feature seems to be under way, see here. At the moment you have to write your own table, something like

data = [[{:image => "red.png"},{:text => "Red"}],
        [{:image => "blue.png"},{:text => "Blue"}]]
data.each_with_index do |row,i|
  row.each_with_index do |cell,j|
    bounding_box [x_pos,y_pos], :width => cell_width, :height => cell_height do
      image(cell[:image], ...) if cell[:image].present?
      text_box(cell[:text], ...) if cell[:text].present?
    end
    x_pos = (x_pos + cell_width)
  end
  y_pos = (y_pos - cell_height)
end
浅浅 2024-12-22 01:44:50

0.12.0 版本中的 Prawn 无法在单元格中插入图像。查看更多信息。它适用于下一个版本 1.0.0.rc1。只需更改您的版本即可。你也可以使用trick的方式,但我建议你不要这样做。
该手册可在此处获取。

作者对该功能的提交和解释。 这里

Prawn in version 0.12.0 doesn't give the possibility to insert image in a cell. Look at this for further information. It works on the next version 1.0.0.rc1. Just change your version. You can also use the tricky way, but I advise you not to do so.
The manual is available here.

The commit and explanation for that feature from the author. Here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文