In your OnEndPage
method, you have this line:
head.WriteSelectedRows(0, -1, 10, page.Height - cellHeight + head.TotalHeight - 30, writer.DirectContent);
This code correctly calculates where to place content based on page height and top margin, but also includes magic 30
, in which the title lights up on top of the table. Change it to this and your headline will be fine.
head.WriteSelectedRows(0, -1, 10, page.Height - cellHeight + head.TotalHeight, writer.DirectContent);
I assume that this 30
trying to include some addition between your heading and the table itself. What I would recommend actually modifies the document fields themselves in the main code:
document.SetMargins(document.LeftMargin, document.RightMargin, document.TopMargin + 30, document.BottomMargin);
And then, given this in the OnEndPage
method:
float cellHeight = document.TopMargin - 30;
The footer code does not actually take into account the lower limit and simply draws it at 50
, so this will always overlap. A quick fix would be to change it to:
footer.WriteSelectedRows(0, -1, 10, footer.TotalHeight, writer.DirectContent);
This will at least lead to the alignment of the footer. If you want some more additions as described above, just change the document fields again:
document.SetMargins(document.LeftMargin, document.RightMargin, document.TopMargin + 30, document.BottomMargin + 30);