Your loop is *outside* the bounding box, re-setting the top left
corner each time.
try:
pdf.bounding_box [100,100], :width => 200 do
answers.each_with_index do |answers,i|
pdf.text "Answer + i.to_s" + i.to_s + ":" + answers
end
end
To put padding between the text, check out pad(), pad_bottom(),
pad_top(), and move_down()
-greg
--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com
If that's what you're getting, your code is actually more complicated
than the examples you've shared.
I'm not sure that you're intentionally putting your text at the bottom
of the page. Y=0 is at the bottom margin in Prawn. (Or the bottom of
any bounding box you create)
require "rubygems"
require "prawn"
pdf = Prawn::Document.new
answers = ["Yes it is", "No it isn't"]
pdf.bounding_box [100,pdf.bounds.top-100], :width => 200 do
answers.each_with_index do |answer,i|
pdf.text "Answer #{i}: #{answer}"
end
end
pdf.render_file "foo.pdf"
Your example works exactly as I need, but I somehow can't get it to
work in my code. I'm travelling this week and don't have much time to
take a careful look, I'll get back to this next week.
Thanks a lot for your help!
esti
On Thu, Aug 28, 2008 at 4:28 PM, Gregory Brown
As I said, I can't get this to work. I think the problem is that I
have text before and after this block. Can you please have a look at
this example?
require "rubygems"
require "prawn"
pdf = Prawn::Document.new
pdf.text "Some stuff"
pdf.text "Some stuff"
pdf.text "Some stuff"
pdf.text "Some stuff"
pdf.text "Some stuff"
pdf.text "Some stuff"
pdf.text "Some stuff"
answers = ["Yes it is", "No it isn't"]
pdf.bounding_box [100,pdf.bounds.top-10], :width => 200 do
answers.each_with_index do |answer,i|
pdf.text "Answer #{i}: #{answer}"
end
end
pdf.text "More stuff"
pdf.render_file "foo.pdf"
I would expect "Some stuff" lines to go first, then "Answers" below,
and then "More stuff" below, but I see everything cluttered up.
Anybody?
If you place the bounding box 10 points from the top of your page (as
you are here, look at the top-left corner of the box), why would you
expect this?
I think what you want is:
pdf.bounding_box [100, pdf.y - pdf.bounds.absolute_bottom], ...
-greg