Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while inserting image in table using Prawn

Tags:

pdf

prawn

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!

like image 315
verdure Avatar asked Nov 11 '11 05:11

verdure


1 Answers

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
like image 144
0x4a6f4672 Avatar answered Oct 21 '22 07:10

0x4a6f4672