4
votes

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!

2
verdure, did you ever figure this out or find a way around it? - derick

2 Answers

4
votes

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
4
votes

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