Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prawn - Adding an image along with text in a table cell

Is it possible to embed an image along with a text in a table cell using gem prawn?

I'm using gem "prawn", "~> 0.13.2"

I could embed either an image or a text only. But, not both. please help.

Rails version: 3.2.13 and Ruby 2.0.0

like image 262
Rajesh Omanakuttan Avatar asked Mar 20 '23 23:03

Rajesh Omanakuttan


1 Answers

Here is code from the manual on how to insert an image, and a text into a PDF-document:

text "Scale by setting only the width"
image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 150
move_down 20

text "Scale by setting only the height"
image "#{Prawn::DATADIR}/images/pigs.jpg", :height => 100
move_down 20

text "Stretch to fit the width and height provided"
image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 500, :height => 100

Here is code from the manual on how to insert an image, and a text into a table cell of a PDF-document:

cell_1 = make_cell(:content => "this row content comes directly ")
cell_2 = make_cell(:content => "from cell objects")
two_dimensional_array = [ ["..."], ["subtable from an array"], ["..."] ]
my_table = make_table([ ["..."], ["subtable from another table"], ["..."] ])
image_path = "#{Prawn::DATADIR}/images/stef.jpg"

table([ ["just a regular row", "", "", "blah blah blah"],
    [cell_1, cell_2, "", ""],
    ["", "", two_dimensional_array, ""],
    ["just another regular row", "", "", ""],
    [{:image => image_path}, "", my_table, ""]])

For more information on customizing a table cell image: Check out the Prawn documentation

like image 178
Малъ Скрылевъ Avatar answered Apr 02 '23 15:04

Малъ Скрылевъ