column_box question

133 views
Skip to first unread message

RNHurt

unread,
May 8, 2009, 2:50:22 PM5/8/09
to Prawn
I am creating a report card that has two columns and as I perused
around the Prawn source code I found a new type of bounding_box called
column_box that looks like it will do exactly what I need. Using a
simple text test everything works great, however tables don't flow to
the next column.

This works fine:
column_box [0,cursor], :width => bounds.width, :columns => 2
do
text " This is a test " * 100
end

This just causes the tables to continue in the first column over
multiple pages, never flowing into the second column:
column_box [0,cursor], :width => bounds.width, :columns => 2
do
table data, :headers => headers,
:header_color => 'C0C0C0',
:font_size => 7,
:border_style => :grid,
:border_width => 0.5,
:width => bounds.width-10
end

I know column_box is a new, unstable feature but I thought I would ask
about it anyway and see if I'm barking up the wrong tree trying to use
it with tables.

Thanx!
Richard

Gregory Brown

unread,
May 8, 2009, 3:06:15 PM5/8/09
to prawn...@googlegroups.com
On Fri, May 8, 2009 at 2:50 PM, RNHurt <rnh...@gmail.com> wrote:

> I know column_box is a new, unstable feature but I thought I would ask
> about it anyway and see if I'm barking up the wrong tree trying to use
> it with tables.

Yeah, I had no plans to test to see if tables work in it. It doesn't
surprise me that they don't.

But patches are welcome, and please file a ticket on github to remind
me to note this issue in the documentation until then.

-greg

Paul

unread,
May 9, 2009, 8:28:14 AM5/9/09
to Prawn
Can you describe a bit more what you'd like to see? I'm not sure I
understand.

RNHurt

unread,
May 10, 2009, 7:41:34 AM5/10/09
to Prawn
Sure, my report is basically two columns each containing multiple
boxes stacked one on top of the other. Each box contains information
about a course that the student has taken (name, grade, comments,
etc.). So on any one page there could be 5-6 variable sized boxes,
2-3 in each column. Something like this:

------------ -------------
| Name | | Name |
| Grade | | Grade |
| Comments | | Comments |
| | | |
------------ -------------
------------ -------------
| Name | | Name |
| Grade | | Grade |
| Comments | | Comments |
| | -------------
------------ -------------
------------ | Name |
| Name | | Grade |
| Grade | | Comments |
| Comments | -------------
| Comments |
| |
------------


Instead of trying to stack them up and position them manually I
thought I could make use of the column_box function. But it appears
as if that function only works with text objects and not table
objects. :( I took a look at the source code but I'm afraid I'm not
a good enough Ruby developer to understand it all.

I hope that helps a bit.

Thanx!
Richard

BTW: I've opened a new issue (http://github.com/sandal/prawn/
issues#issue/11) for this problem.

amoeba

unread,
May 10, 2009, 11:51:37 AM5/10/09
to Prawn
I think I understand what you're looking for. Here's one way I think
you could tackle your problem:

http://gist.github.com/109631

RNHurt

unread,
May 11, 2009, 10:22:37 AM5/11/09
to Prawn
Thanks for the code - it does indeed give me some ideas.
Unfortunately I see that your code is based on a fixed number of rows
per page (3 I think) and my report is trying to put as many boxes on
each page as possible. Also the boxes can have different contents and
different heights. That makes it even tougher. :/

Thanx!
Richard

amoeba

unread,
May 11, 2009, 1:41:03 PM5/11/09
to Prawn
I see. Here's another stab:

http://gist.github.com/110063

But I've run into a problem I don't yet understand. If the number of
tables in the columns gets too large, very funky things start to
happen. The only solution I can think of would be to perform
calculations (nasty ones) to estimate the size of each table you put
out. Something like:

size_of_table = constant * number_of_rows in table + size_of_header

I think you could end up with pretty good accuracy with an approach
like that. If a table will spill over the page, just start_new_page
and keep going.
Reply all
Reply to author
Forward
0 new messages