tags:

views:

262

answers:

1

I'm trying to layout 6 images per page with prawn in Ruby:

case (idx % 6) # ugly                                                                                                                                                                                 
  when 0 : (pdf.start_new_page; pdf.image img, :position => :left, :vposition => :top, :width => 270)
  when 1 : pdf.image img, :position => :right, :vposition => :top, :width => 270
  when 2 : pdf.image img, :position => :left, :vposition => :center, :width => 270
  when 3 : pdf.image img, :position => :right, :vposition => :center, :width => 270
  when 4 : pdf.image img, :position => :left, :vposition => :bottom, :width => 270
  when 5 : pdf.image img, :position => :right, :vposition => :bottom, :width => 270
end

Not sure what I'm doing wrong, but it prints the first 3 images to the PDF, then creates a new page and prints the last three:

Page 1:

<img>     <img> 
<blank> <blank>
<blank> <blank>

Page 2:

<blank> <blank>
<blank>   <img>
<img>     <img>

Any suggestions would help.

A: 

Image is going to flow (like text does) when you aren't explicitly positioning items.

Wrap each call in a float() { ... } and that will do the trick. Alternatively, use prawn/grid for positioning.

Gregory Brown