There's a method in PdfWriter
called getVerticalPosition()
. It takes a Boolean parameter that tells iText to ensure a new line or not. If you don't ensure a new line (false
), you get the current Y, but that may not be the position you need. If you ensure a new line (true
), a new line is added and you get the position where the new line starts.
As you are creating A4 pages from start, and as the Y axis points upwards, you need to subtract the bottom margin from this vertical position to find out how much space is left for your new table.
Note that we aren't happy with the getVerticalPosition()
method at iText: having a getter that changes the content of the document isn't very elegant. In cases like yours, we prefer working with ColumnText
to take charge over the layout process intstead of letting iText decide where to split a table.