9

I'm trying to position some content vertically centered in a bounding_box. With a single text this is no problem:

bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
  text "vertically aligned in the surrounding box", :valign => :center
end

But what can I do if a have multiple elements in my bounding box:

bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
  text "vertically aligned in the surrounding box", :valign => :center
  text "vertically aligned in the surrounding box", :valign => :center
end

That won't work, the text is overlaid when you try this...

I'm looking for a way to group the whole content of the bounding_box and then align that whole group vertically. Is there any way to do this with prawn??

Thanks a lot for your help! Chris

peter
  • 41,770
  • 5
  • 64
  • 108
Chris Crown
  • 304
  • 2
  • 13

1 Answers1

7

If you only have text lines, you can still use formatted_text with \n in your text :

formatted_text [
    { text: "#{line1}\n" },
    { text: "#{line2}" }
  ],
  valign: :center,
  leading: 6

I'm still trying to figure out how to handle a picture/legend group, since even tables don't seem to do the trick.

ejoubaud
  • 5,013
  • 6
  • 37
  • 39