7

I am using PdfPTable to create a table in pdf.I have a single row in the table.In my row last column has data which has height more than remaining height of the page.So row is getting started from the next page while table headers are on the previous page and there is large blank space below the header on the first page.

Can anybody suggest how can i split the row over multiple page.

Thanks

Manish
  • 1,274
  • 3
  • 22
  • 59

1 Answers1

17

Please read chapter 4 of my book or browser the documentation that is abundant on the iText site.

By default, table rows aren't split. iText will try to add a complete row to the current page, and if the row doesn't fit, it will try again on the next page. Only if it doesn't fit on the next page, it will split the row. This is the default behavior, so you shouldn't be surprised by what you see in your application.

You can change this default behavior. There's a method that will allow you to drop content that doesn't match (this is not what you want) and there's a method that will allow you to split rows when they don't fit the current page (this is what you want).

The method you need is used in the HeaderFooter2 example:

PdfPTable table = getTable(...);
table.setSplitLate(false);

By default, the value of setSplitLate() is true: iText will split rows as late as possible. By changing this default to false, iText will split rows immediately.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • 1
    Thanks a lot Bruno.It's Working absolutely fine now. – Manish Feb 27 '14 at 11:09
  • According to doc If splitlate is true the row will only split if it's the first one in an empty page. I didn't get this line.Does it mean that if it is the first row then only it will split. – Manish Feb 27 '14 at 11:16
  • 1
    **Rule 1:** If you set split late to `true`, iText will not split a row, but forward it to the next page. However: suppose that a row doesn't fit a page, then you'd have an endless loop, because you'd always forward the row to the next page. That's why the **Rule 1** needs to be amended with **Rule 2**: if a row is the first row on an otherwise empty page, the row will be split anyway. – Bruno Lowagie Feb 27 '14 at 12:33
  • but i think i need to remove pTable.keepRowsTogether( 0, contentList.size() - 1 ); lso from my code. right ? because it's keeping my rows together. – Manish Feb 27 '14 at 14:54
  • 1
    Yes, that line needs to be deleted (I didn't know it was there because you didn't share any code). – Bruno Lowagie Feb 27 '14 at 18:11