flowing bounding boxes within page

10 views
Skip to first unread message

mirec

unread,
May 26, 2009, 2:38:51 PM5/26/09
to Prawn
Hi

i have blocks of texts (song lyrics) and i want to have 2 of them on
one page if they fit, if not, whole second bounding_box (song) should
be moved to next page.

thx for help

Gregory Brown

unread,
May 26, 2009, 2:46:11 PM5/26/09
to prawn...@googlegroups.com

plzgivemethecodes

mirec

unread,
May 26, 2009, 2:53:00 PM5/26/09
to Prawn
this is relevant extract of my code:

results = Song.find(:all, :order => 'chorus,title')
Prawn::Document.generate(file_name, :page_size => "A5", :page_layout
=> :portrait) do
results.each do |result|
height = 15
song = lazy_bounding_box([0,530], :width => 350) do
font font_gbi
text counter.to_s + '. ' + "#{result.title}",:align
=> :left, :size => title_size, :kerning => true
(1...12).each do |t|
t = t.to_s
s = eval('result.strofa'+t)
unless s.blank? or s == ' '
s = s.chomp.chomp.chomp.chomp
move_down(8)
font font_g
text t + ". " + s, :align => :left, :spacing =>
2, :size => text_size, :kerning => true
move_down(4)
height = height + height_of(t + ". " + s,
line_width) + 10
end
r = eval("result.refren"+t)
unless r.blank? or r == ' ' or r == ' '
r = r.chomp.chomp.chomp.chomp
move_down(4)
font font_gbi
text "Refrén", :align => :left, :spacing =>
2, :size => text_size-1, :kerning => true
move_down(2)
font font_gi
text r, :align => :left, :spacing => 2, :size =>
text_size, :kerning => true
end
end
move_down(4)
start_new_page
song.draw
end
end
end

MRoderick

unread,
May 26, 2009, 2:53:01 PM5/26/09
to Prawn
> plzgivemethecodes

heh

Gregory Brown

unread,
May 26, 2009, 2:59:37 PM5/26/09
to prawn...@googlegroups.com
Look at how table determines whether to go to the next page or not for
each new row in prawn-layout.
You'll need something like that.

-greg
--
BOOK: http://rubybestpractices.com
TECH: http://blog.majesticseacreature.com
NON-TECH: http://metametta.blogspot.com

mirec

unread,
May 26, 2009, 3:07:32 PM5/26/09
to Prawn
so i have to use tables, not bounding boxes to achieve this?

Gregory Brown

unread,
May 26, 2009, 3:11:37 PM5/26/09
to prawn...@googlegroups.com
On Tue, May 26, 2009 at 3:07 PM, mirec <miro.z...@gmail.com> wrote:
>
> so i have to use tables, not bounding boxes to achieve this?

No. I suggested you should look at the source to see how it works,
since tables are also built on top of bounding boxes.

Reply all
Reply to author
Forward
0 new messages