views:

233

answers:

2

I have a document with dynamic image and dynamic text and would like the text around the image. The image is right aligned on the landscape page. Here is what I have so far:

pdf.bounding_box([0,pdf.bounds.top - 50], :width => pdf.bounds.width, :height => pdf.bounds.height-50) do
  pdf.text @article.title, :size => 30, :style => :bold
  pdf.text @article.content, :align => :left
  # image
  pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], :width => 250, :height => 250) do
    pdf.image image_path, :width => 250
  end
end

The text goes right underneath the image. I tried doing this http://stackoverflow.com/questions/2085151/ruby-prawn-how-to-wrap-text-around-an-aligned-right-image but it didn't work.

Help is appreciated, thanks.

A: 

I don't have much experience with prawn, so this is just a guess. Have you tried putting your pdf.text statements after the image bounding box?

pdf.bounding_box([0,pdf.bounds.top - 50], 
   :width => pdf.bounds.width, 
   :height => pdf.bounds.height-50) do 

   # image 
   pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], 
      :width => 250, :height => 250) do 
      pdf.image image_path, :width => 250 
   end 

   pdf.text @article.title, :size => 30, :style => :bold 
   pdf.text @article.content, :align => :left 

end
ghoppe
Good idea but that just makes the text start below the image and not in line with it. If I call move_up beforehand then the text goes in front of the image.
stevenheidel
OK thanks, just taking a stab. Looks like that stack overflow link you posted was wrong then?
ghoppe
Yep it didn't seem to work for me.
stevenheidel
+1  A: 

If you know the width and height of the image, you can use text_box to position a text box next to the image, and collect the returned string of the text that did not fit. Then create a second text box or an ordinary text() call below the image and text_box, and you should be good to go.

This example should help: http://github.com/sandal/prawn/blob/0.9.1/examples/text/text_box_returning_excess.rb

Gregory Brown
I'll give that a try.
stevenheidel