I'm using iTextSharp v5.3 to build a PDF with one or more tables that are have the same cells but can vary in height due to dynamic content. Currently, if a PdfPTable
is too large to fit on the current page the table is broken and the remaining cell data ends up on the next page. Is there a way I can tell iTextSharp that if the table won't fit, to put the whole thing on the next page?
I've tried messing around with SplitRows
and SplitLate
but they don't have the desired effect. I have also tried to do some calculations after adding the PdfPTable
to the document but can't figure out how to get the "cursor position" on the page. Do I need to track the current page's height in my loop and do all of the calculations myself?
You can also use:
tableName.KeepTogether = true;
You can ask the table for its total height. This is done like this: table.TotalHeight
If the height is 0, make sure you've defined the width first: iText can't calculate the width if it doesn't know the available width to render the table.
Once you have the height, ask the writer for the vertical position: writer.GetVerticalPosition(true)
As you probably know, the Y coordinate is 0 at the bottom of the page. If the vertical position minus the total height of the page exceeds the margin size, you know that the table won't fit, and you can trigger a new page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With