How to get the size of a grid box

33 views
Skip to the first unread message

Wagner Matos

unread,
9 Jan 2016, 19:56:2109/01/2016
to Prawn
I'm trying to use grids to create ads within a page. Lets say I have a page with 5 columns and 5 rows.

I'd like to dynamically calculate the size of each subsequent box within the grid so I can - for instance - use an image to fit the whole width of the box. I've tried the following:

Prawn::Document.generate("test.pdf") do |pdf|
  pdf
.define_grid(:columns => 5, :rows => 5, :gutter => 10)
  pdf
.grid(7, 1).bounding_box do
    pdf
.stroke_bounds
    pdf
.text "Some text"
    pdf
.image open("image_url"), :fit => [dynamic_size, dynamic_size]
 
end
end

Ideally I'd like the ability to use percentage in the
:fit =>[100%, 30%]

parameters (or a method to calculate this percentage on the fly). 

Any ideas how can I achieve this?

Thanks in advance!
Reply all
Reply to author
Forward
0 new messages