Search code examples
ruby-on-railsrubypdf-generationprawnprawnto

ruby prawn how to wrap text around an aligned right image?


s it posible to align an image to the right and wrap text around the image like it is in html and css using the float:right property ?

If so how do you do this ?

I can align an image but dont't know how to wrap the text around it. The text is dynamic text therefore varies alot in length.

Thanks alot Rick


Solution

  • One suggestion is to try nested bounding boxes. The main bounding box would have the text inside it. with at some point another bounding box for the image. Something along the lines of

    bounding_box([x,y], :width => bounds.width, :height => 400) do
        text "blah"
        text "blah"
        # image
        bounding_box([bounds.right - image_width, 0], :width => image_width) do
              image("path_to_file", :at => [0,0], :width =>  bounds)
        text "more blah"
    
    
    end
    

    You may be able to simply use the image without the bounding box, but the bounding box would ensure that the text flows around it.