I do have an iteration for creating a form with many fields. When I add about 20 fields (TextField and others) among each other it is bigger then one page. How do I calculate the page size that all fields are compartmentalized into pages with correct page size.
Would you please share your complete sample code snippet along with output PDF document you generated at your side. We will test the scenario in our environment and address it accordingly.
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.SetPageSize(PageSize.A4.Width, 360+400+300);
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
Thanks for your efforts. I do have two problems with that solution:
I some cases I do have a dynamic size of the item control. So I cannont set the page height to a static value. Is there any option to calculate the size of a TextBox (here used as label) after I have added it to a page?
What I need is a pagebreak. When I set the page height to > PageSize.A4.Height it is higher than PageSize.A4.Height (of cource, I did set it). But what I want is that the page height stays at PageSize.A4.Height and the controls are positioned automaticly to the next page.
Once you add the textbox inside PDF, you can use getHeight() method to get height of textbox.
In your above particular scenario, we would like to suggest you to please use tables. You can add textbox inside table cell and add as many rows inside tables as you want with textboxes in them. By default table would shift to subsequent pages after it reaches to maximum available page height. For more information, you may also visit Add Table article in API documentation.