我正在与 Prawn 一起生成 pdf,我必须在表格的单元格中插入图像。
我的代码是这样的:
image = "path to file"
subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"],
[formative_1,sumative, {:image => image}]
]
table subject
Run Code Online (Sandbox Code Playgroud)
但是,我收到一条错误消息:
prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?任何帮助是极大的赞赏。
干杯!
在当前版本的 Prawn 中,0.12.0无法在 a 中嵌入图像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
Run Code Online (Sandbox Code Playgroud)