Error inserting image into table using shrimp

I work with shrimp to create a pdf file, I need to insert an image into a table cell.

My code looks like this:

image = "path to file" subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"], [formative_1,sumative, {:image => image}] ] table subject 

But I get an error message:

  prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError) 

How can i solve this? Any help is appreciated.

Hooray!

+4
source share
2 answers

In the current version of Prawn 0.12.0 it is not possible to insert images into Prawn::Table , but this function seems to be already running, see here . At this point you need to write your own desk, 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
source

Shrimp in version 0.12.0 does not allow you to insert an image into a cell. Take a look at this for more information . It works in the next version 1.0.0.rc1 . Just change your version. You can also use the tricky way, but I advise you not to. The manual is available here .

Transfer and explanation of this function from the author. Here

+4
source

Source: https://habr.com/ru/post/1380703/


All Articles