Tables printed side-by-side

54 views
Skip to first unread message

Valerie

unread,
Nov 5, 2009, 12:02:21 PM11/5/09
to Prawn
I'm trying to position 2 tables next to each other using mask(:y){}.
It works perfectly as long as the table on the left is less than a
page long, but if the table goes longer than a page, then the top of
the right table starts at the top of the left table's last page
instead of at the top of the left table.

So, perhaps mask(:y){} isn't the right way to do it. Can anyone
suggest a better way to print two long tables next to each other?

Here is a script that demostrates the side-by-side behavior that I
want, and another example that shows that it won't be side-by-side if
the left table is longer than one page:

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

def two_tables(left_number, right_number, output_file)
Prawn::Document.generate(output_file) do
left_table_data, right_table_data = [], []
left_number.times do |i|
left_table_data << [ i, "table on the", "left side" ]
end
right_number.times do |j|
right_table_data << [ "right side table", j ]
end

left_table_options = { :headers => ["", "Title 1", "Title
2"], :border_style => :grid }
mask(:y) { table left_table_data, left_table_options }

right_table_options = { :headers => ["Title 1", "Title
2"], :position => 200 }
table right_table_data, right_table_options
end
end

two_tables(5, 5, "side_by_side.pdf") # This is what I'm
trying to achieve
two_tables(35, 5, "not_side_by_side.pdf") # This one doesn't do
what I want
Reply all
Reply to author
Forward
0 new messages