Thanks for sharing sample project.
We have checked the sample project and would like to suggest you that you can set page height equal to the sum of textboxes height and bottom/top margin between them. In your particular scenario, you are adding 40 Textboxes having 20 margin value between each pair;
// 20 TextBoxes => Height = 18 => Total = 360
// 20 TextBoxes => Height = 15 => Total = 300
// 20 Margin between => Total = 400
// Total Page Height => 360 + 300 + 400
You can set page height right after adding page to the document using following line of code. An output PDF is also attached for your reference.
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
tmpC13C.pdf (23.2 KB)
In case of any further assistance, please feel free to let us know.