How to split a row over multiple pages?

I am using PdfPTable to create a table in PDF. I have a single row in the table. In my row, the last column has data which has a height that needs more space than remaining height of the page. So t

I am using PdfPTable to create a table in PDF. I have a single row in the table. In my row, the last column has data which has a height that needs more space than remaining height of the page. So the row is getting started from the next page while the table headers are on the previous page and there is large blank space below the header on the first page. Can anybody suggest how I can split the row over multiple pages?

Posted on StackOverflow on Feb 27, 2014 by Manish

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.


Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now