Table spanning multiple pages. Finish table with horizontal line

398 views
Skip to first unread message

Brian Jensen

unread,
Jan 29, 2013, 7:52:32 AM1/29/13
to prawn...@googlegroups.com
Hi guys, 

I have a table that spans two pages. When the table finishes off one page to begin on the other, there is no horizontal line to 'finish' the table on page 1, so it looks like rows have been omitted. How can I get this?

I am using header: true as an option to get the headers back on page 2, thats awesome.

Any ideas on how I can get prawn to add the horizontal line on the bottom of page 1?

Thanks in advance.

Brian

Brian Jensen

unread,
Jan 29, 2013, 8:12:01 AM1/29/13
to prawn...@googlegroups.com
I checked out table#before_rendering_page

The example states: 

t.before_rendering_page do |page|
  page.row(0).border_top_width = 3
  page.row(-1).border_bottom_width = 3
  page.column(0).border_left_width = 3
  page.column(-1).border_right_width = 3
end

That wraps the entire table inside a frame, so I need   

t.before_rendering_page do |page|
  page.row(-1).border_bottom_width = 3
end

Except row(-1) should be the last visible row on the current page. Anyone know how I can fetch that?

Thanks in advance

Brad Ediger

unread,
Jan 29, 2013, 9:19:28 AM1/29/13
to prawn-ruby
On Tue, Jan 29, 2013 at 7:12 AM, Brian Jensen <bria...@gmail.com> wrote:
> t.before_rendering_page do |page|
> page.row(-1).border_bottom_width = 3
> end
>
> Except row(-1) should be the last visible row on the current page. Anyone
> know how I can fetch that?

If I understand your question correctly, that's exactly what
page.row(-1) means. The code you pasted should use a 3-pt bottom
border on the last row of every page.

-be

Brian Jensen

unread,
Jan 29, 2013, 9:57:11 AM1/29/13
to prawn...@googlegroups.com
Hi Brad, 

Thank you for for your quick response.

This is my code: 

class PrawnTest
  def initialize()
  end

  def test_table
    pdf = Prawn::Document.new
    data = []
    40.times do 
      data << ["Hello", "world"]
    end
    pdf.table(data, :cell_style => {:border_width => 0.1, borders: [:left, :right ], :inline_format => true, padding: 5 } ) do |t|
      t.before_rendering_page do |page|
        page.row(0).border_top_width = 3
        page.row(-1).border_bottom_width = 3
        page.column(0).border_left_width = 3
        page.column(-1).border_right_width = 3
      end
    end
    pdf.render_file "table.pdf"
  end
end

With the latest code from github, no border bottom on the current page.

Thank you in advance

Best regards
Brian

Brad Ediger

unread,
Jan 29, 2013, 10:02:10 AM1/29/13
to prawn-ruby
On Tue, Jan 29, 2013 at 8:57 AM, Brian Jensen <bria...@gmail.com> wrote:
> pdf.table(data, :cell_style => {:border_width => 0.1, borders: [:left,
> :right ], :inline_format => true, padding: 5 } ) do |t|
> t.before_rendering_page do |page|
> page.row(0).border_top_width = 3
> page.row(-1).border_bottom_width = 3
> page.column(0).border_left_width = 3
> page.column(-1).border_right_width = 3
> end
> end

(snip)

> With the latest code from github, no border bottom on the current page.

The problem is that borders: [:left, :right] applies to all cells, so
even though you're setting a width of the bottom borders, they are not
being drawn. Cell borders must have both a width and a corresponding
entry in :borders to be drawn.

-be

Brian Jensen

unread,
Jan 29, 2013, 10:14:43 AM1/29/13
to prawn...@googlegroups.com
Hi Brad, 

You are right! Setting the border width to 0 worked. Thanks mate.


Here is the working program.

class PrawnTest
  def initialize()
  end

  def test_table
    pdf = Prawn::Document.new
    data = []
    40.times do 
      data << ["Hello", "world"]
    end
    pdf.table(data, :cell_style => {:border_width => [0, 0.1, 0, 0.1], borders: [:left, :right, :top, :bottom], :inline_format => true, padding: 5 } ) do |t|
      t.before_rendering_page do |page|
        page.row(0).border_top_width = 3
        page.row(-1).border_bottom_width = 3
        page.column(0).border_left_width = 3
        page.column(-1).border_right_width = 3
      end
    end
    pdf.render_file "table.pdf"
  end
end
Reply all
Reply to author
Forward
0 new messages