Table + footer at end of last page only, without overlap?

695 views
Skip to first unread message

Henrik N

unread,
Oct 8, 2009, 8:08:27 AM10/8/09
to Prawn
I want a PDF document with a table followed by a footer of sorts. The
table may span several pages, and on the last page, there should be a
footer (a "sign on the dotted line" type thing) at the page bottom
(not out in the margins).

The footer may be on a page of its own if there's no room for it at
the bottom of the last page of the table.

If I just do pdf.table followed by a bounding_box positioned at
bottom, then the table and footer may overlap. See the example at the
end of the mail (Pastie: http://pastie.textmate.org/private/k0643puqyludym04fzmpqw).
Currently using Prawn 0.5.1 but can probably use edge if necessary.

I suppose I could compare the top coordinate of the footer with the
bottom coordinate of the table and insert a page break if they
overlap, but I'm sure there is a better way.

I'm guessing I shouldn't be using a bounding_box, but I'm not sure
what I should be using. The example below is, of course, simplified.
The real footer contains several text bits and dotted lines.

The code example:


LINE_COUNT = 30

require 'rubygems'
require 'prawn'
require "prawn/layout"

pdf = Prawn::Document.new(:page_size => "A4")

pdf.table [["Foo", "Bar"]] * LINE_COUNT

pdf.bounding_box([0, 100], :width => pdf.bounds.width, :height => 100)
do
pdf.stroke_bounds
pdf.text "Sign here:"
end

pdf.render_file('prawn.pdf')

# OS X
`open prawn.pdf`

Henrik N

unread,
Oct 8, 2009, 8:54:10 AM10/8/09
to Prawn

On Oct 8, 2:08 pm, Henrik N <hen...@nyh.se> wrote:
> I suppose I could compare the top coordinate of the footer with the
> bottom coordinate of the table and insert a page break if they
> overlap, but I'm sure there is a better way.

Did that for now:

table …

FOOTER_HEIGHT = 60.mm

table_bottom_y = y - bounds.absolute_bottom
start_new_page if table_bottom_y < FOOTER_HEIGHT

bounding_box([0, FOOTER_HEIGHT], :width => bounds.width, :height =>
FOOTER_HEIGHT) do

end

Do let me know if there's a better solution, though.

Gregory Brown

unread,
Oct 8, 2009, 8:56:31 AM10/8/09
to prawn...@googlegroups.com

This looks okay to me. What do you imagine a better solution to look
like? If you can come up with an idea, maybe we could work from
there.

-greg

Henrik N

unread,
Oct 8, 2009, 10:07:52 AM10/8/09
to Prawn


On Oct 8, 2:56 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> This looks okay to me.  What do you imagine a better solution to look
> like?  If you can come up with an idea, maybe we could work from
> there.

Thanks for the reply.

I suppose I was hoping for something like (pseudo-code)

box(:width => bounds.width, :height => 60.mm, :valign => :bottom) do
end

Basically, being able to float a container to the bottom and still
have it be part of the flow of the page, so elements don't overlap.
But that may be too rare a use case to generalize.

Gregory Brown

unread,
Oct 8, 2009, 10:14:52 AM10/8/09
to prawn...@googlegroups.com

Not necessarily. If you want to try patching this, go for it. We
probably need to come up with a better name than box() though.
Perhaps container() would work, though I'm not in love with that
either.

-greg

Reply all
Reply to author
Forward
0 new messages