Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prawn PDF - How to get the height of a text box

I have a formatted_text_box that contains dynamic text. It seems like the box just expands nicely when not given specific dimensions.

The problem is it doesn't seem to move the cursor to the bottom of the box so my text overlaps with the text in the formatted_text_box.

If I could determine the height of the text box I could use move_down accordingly.

Is there any way to determine the height of a text_box on the page?

like image 592
recursive_acronym Avatar asked Mar 26 '13 19:03

recursive_acronym


1 Answers

Expanding on Abraham's stubbed answer:

  1. create the formatted text box, making sure to pass in options you normally pass to the helper method pdf.formatted_text_box

    features_box = ::Prawn::Text::Formatted::Box.new(feature_text.flatten, {
        at: [@pdf.bounds.left + 3.in, @pdf.bounds.top - 0.7.in],
        inline_format: true,
        document: @pdf
      }
    )
    
  2. dry_run the box features_box.render(dry_run: true)

  3. grab the box height @height = features_box.height

  4. render the box for real features_box.render
  5. move the cursor or start another box at the new height
like image 177
RobinSH Avatar answered Oct 24 '22 00:10

RobinSH