我正在与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)
我该如何解决这个问题?任何帮助是极大的赞赏。
干杯!
答案 0 :(得分:4)
在当前版本的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
答案 1 :(得分:4)
版本0.12.0
中的Prawn无法在单元格中插入图像。请看further information。它适用于下一个版本1.0.0.rc1
。只需更改您的版本。您也可以使用这种棘手的方式,但我建议您不要这样做。
该手册可用here。
作者对该功能的提交和解释。 Here