Change Table Height for Multiple Pages

34 views
Skip to first unread message

Adam Lukens

unread,
Feb 13, 2014, 11:07:20 AM2/13/14
to prawn...@googlegroups.com
Hi all,

Our existing bank statement process had become a bit cumbersome, and we decided we were going to transition it to Ruby. It's been an utter joy to use Prawn, but I've run into a bit of a snag. 

On the first page of our statements, we have a number of statistics about past payments, current balance, etc. as well as the start of a list of transactions. This list of transactions has room for four lines, and then needs to continue onto the next page. Unfortunately, it's currently in the middle of the document like so:  


My understanding is that you can wrap a table in a bounding box to accomplish the first page's worth of transactions. I've tried the following, and can get the transaction list to fit just where I want on page one. Unfortunately, it repeats in the same location on all pages, when I'd rather reset the bounding box dimensions for anything page two and beyond.

Prawn::Document.generate(filename="example.pdf") do |pdf|
  data = [["Column 1", "Column 2", "Column 3", "Column 4"]]
  100.times {|i| data << ["Row #{i}", "Row #{i}", "Row #{i}", "Row #{i}"]}

  x = 100
  y = 600
  width = 500
  height = 400

  box = pdf.bounding_box([x, y], :width => width, :height => 400) do
    pdf.table(data, {:header => true}) do |t|
      # Set up formatting for the header row
      t.row(0).style :font_style => :bold,
                     :background_color => "000000",
                     :text_color => "FFFFFF"
    end
  end
end

Is there a way to change the size of the bounding box for the second page? Is there a better way of doing this other than simply making two tables and splitting the array into what will fit onto page one?

Thanks,
Adam

Gregory Brown

unread,
Feb 13, 2014, 11:17:21 AM2/13/14
to prawn...@googlegroups.com
My guess is that what you want is a span rather than a bounding box. It
will start anywhere you'd like it to start on the page, but when you go
to the next page it will resume at the top of the document (or whatever
the outer bounding box is).

There are examples in the free_flowing_text.rb section of the manual on
page 33: http://prawnpdf.org/manual.pdf

-greg

On 2/13/14 11:07 AM, Adam Lukens wrote:
> Hi all,
>
> Our existing bank statement process had become a bit cumbersome, and we
> decided we were going to transition it to Ruby. It's been an utter joy
> to use Prawn, but I've run into a bit of a snag.
>
> On the first page of our statements, we have a number of statistics
> about past payments, current balance, etc. as well as the start of a
> list of transactions. This list of transactions has room for four lines,
> and then needs to continue onto the next page. Unfortunately, it's
> currently in the middle of the document like so:
>
>
> <https://lh3.googleusercontent.com/-gdrbW3BVNaM/UvzsMmQYU9I/AAAAAAAAApg/CqDOtr0PA4k/s1600/statement.jpg>
> --
> You received this message because you are subscribed to the Google
> Groups "Prawn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to prawn-ruby+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Adam Lukens

unread,
Feb 13, 2014, 12:09:56 PM2/13/14
to prawn...@googlegroups.com
Thanks, Greg.

I had looked at spans originally, as they would correctly flow onto the next page. However, they ran from the starting point I had set to the bottom of the page. It ended up writing over the payment coupon on the bottom. Here's a slightly more comprehensive example with the coupon at the bottom of page one to illustrate my point: https://gist.github.com/McPolemic/46507cb76fc07875e1b7

The span overwrites the payment coupon at the bottom, but correctly flows to the top of the next page.



The bounding box stays within the constraints I give it, but stays the same size on the next page.

I'm beginning to think the best way is:
1. Measure how many rows can fit on page one (and remeasure if we have layout changes later)
2. Split the array into two arrays, one for page one, and the second for page two and beyond.
3. Add the headers to each array.
4. Make two tables.

I'll admit it's a fairly specific problem. Do you have any other ideas?

Adam

Gregory Brown

unread,
Feb 13, 2014, 12:27:19 PM2/13/14
to prawn...@googlegroups.com
If this were a text box rather than a table, you'd be able to tell it to
render in a constrained box and then return the excess text, which you
could then freely flow on the next page.

Tables probably should have some sort of mechanism that works the same
way, but it's a much more complex system (one that currently has a lot
of bugs, and more features than I'm familiar with).

I wish that I could be more helpful (and maybe someone else here can be)
but I don't have a good answer to your question, and I'd need to do much
more research to be able to give you meaningful advice. However, I'd
appreciate if you open up a ticket at:

https://github.com/prawnpdf/prawn/issues?direction=desc&sort=updated&state=open

The image you included in your first email along with a short
description of the problem should be enough. This qualifies as a "rough
spot" that I'd want to keep tracking, so a ticket will help us look into
this in the future.

-greg

On 2/13/14 12:09 PM, Adam Lukens wrote:
> Thanks, Greg.
>
> I had looked at spans originally, as they would correctly flow onto the
> next page. However, they ran from the starting point I had set to the
> bottom of the page. It ended up writing over the payment coupon on the
> bottom. Here's a slightly more comprehensive example with the coupon at
> the bottom of page one to illustrate my
> point: https://gist.github.com/McPolemic/46507cb76fc07875e1b7
>
> The span overwrites the payment coupon at the bottom, but correctly
> flows to the top of the next page.
>
> <https://lh3.googleusercontent.com/-HOt1pc5HZxQ/Uvz7g2FnzgI/AAAAAAAAApw/LpKWXUaCf_s/s1600/bounding_span-3.jpg><https://lh6.googleusercontent.com/-igeXrVaElgo/Uvz7nO797vI/AAAAAAAAAp4/BP_kUQlVaSA/s1600/example.pdf__page_2_of_4_.jpg>
>
>
>
> The bounding box stays within the constraints I give it, but stays the
> same size on the next page.
>
> <https://lh6.googleusercontent.com/-AyHql2oAvYI/Uvz7wyESPsI/AAAAAAAAAqA/LnFamnLqJBk/s1600/example.pdf__page_1_of_20_.jpg><https://lh3.googleusercontent.com/-TrpkkRU_xFA/Uvz72WMJP6I/AAAAAAAAAqI/UQon5KolR4A/s1600/example.pdf__page_2_of_20_.jpg>
> > an email to prawn-ruby+...@googlegroups.com <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.

Adam Lukens

unread,
Feb 13, 2014, 1:45:06 PM2/13/14
to prawn...@googlegroups.com
Absolutely. I'll file that later today. Thanks for looking into this!

Adam
Reply all
Reply to author
Forward
0 new messages