prawn-table icon indicating copy to clipboard operation
prawn-table copied to clipboard

How to split table with inner table in cell on a new page

Open khataev opened this issue 7 years ago • 2 comments

Prawn::Document.generate("tmp/declaration_#{Time.current.strftime('%H%M%S')}.pdf",
                               page_layout: :landscape) do |pdf|
          arr = []

          1.upto(100) do |n|
            arr << [n,n]
          end

          sub = pdf.make_table arr
          pdf.table [
              ['Chapter1', sub]
          ]
end

Inner table is too long for one page, but second page is not printed. If I remove first column, all is ok. What am I doing wrong?

Prawn::Document.generate("tmp/declaration_#{Time.current.strftime('%H%M%S')}.pdf",
                               page_layout: :landscape) do |pdf|
          arr = []

          1.upto(100) do |n|
            arr << [n,n]
          end

          pdf.table arr
end

khataev avatar May 19 '17 11:05 khataev

You can follow the PR and Issue trail starting at Issue #30 and it links to #16, etc...

From my experience, I and believe this is an open issue, prawn-table does not let a table row span multiple pages. If the content of the table row (or it's child cells, tables, rows, etc) breaks a page, it gets cut off.

In your case, the sub table tries to break the page and stay within the parent cell. Prawn-table will print the first page and basically truncate the rest of the row. When you remove the sub table it works because each row only has the 2 cells of [n,n] and the data is small enough to not span pages. You should be able to get the same result without a sub-table but making the text in one of the cells large enough.

Prawn::Document.generate("tmp/declaration_#{Time.current.strftime('%H%M%S')}.pdf", page_layout: :landscape) do |pdf|
  arr = []

  1.upto(100) do |n|
    arr << [n, ('lorem ipsum' * 10000)]
  end

  pdf.table arr
end

boykoc avatar Jun 01 '17 15:06 boykoc

Is there any news about fixing this issue?

Qew7 avatar May 14 '19 12:05 Qew7