【问题标题】:Error while inserting image in table using Prawn使用 Prawn 在表中插入图像时出错
【发布时间】:2023-04-02 17:00:01
【问题描述】:

我正在使用 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)

我该如何解决这个问题?任何帮助是极大的赞赏。

干杯!

【问题讨论】:

  • verdure,你有没有想过这个问题或找到解决办法?

标签: pdf prawn


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    0.12.0 版本中的虾无法在单元格中插入图像。看看这个further information。它适用于下一个版本1.0.0.rc1。只需更改您的版本。您也可以使用棘手的方法,但我建议您不要这样做。 手册可在here获取。

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

    【讨论】:

      猜你喜欢
      • 2013-11-29
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 2019-10-25
      • 2011-02-02
      • 1970-01-01
      相关资源
      最近更新 更多