Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prawn: Is there a way for vertical alignment of all content in a box?

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

like image 586
Chris Crown Avatar asked Oct 19 '11 20:10

Chris Crown


People also ask

How do I align the contents of a div vertically?

How to Center a Div Vertically. To center a div vertically on a page, you can use the CSS position property, top property, and transform property. Start by setting the position of the div to absolute so that it's taken out of the normal document flow. Then set the top property to 50%.

How many ways can vertical alignment be made?

15 ways to implement vertical alignment with CSS.

How do you align text boxes vertically in HTML?

Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .


1 Answers

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.

like image 88
ejoubaud Avatar answered Sep 25 '22 13:09

ejoubaud