What purpose do ContentArea and AreaGroup serve?
The documentation on the purpose does not really help me.
I'd like to find a way to add mutliple PageElements to some kind of group or "panel" and then i. e. check their combined height to determine if i want them on the current or on the next page.
This would be even better: When I set a new y-position value for that "group" I'd like all elements in that group to update their relative layout/position. Is such a movement of a group possible?
What purpose do ContentArea and AreaGroup serve?
Re: What purpose do ContentArea and AreaGroup serve?
Support · Mar 11, 2016Hello,
The area group is designed to give the ability to set a height and width on page elements that do not have the height and width defined. Also you can add multiple page elements to PDF page using AreaGroup. You can refer to the more details on AreaGroup here
.
You will need to add the page elements to the AreaGroup by specifying the positions and dimensions. Also you will need to place the page elements one below the other or besides one another by specifying the calculated X and Y positions and keep track of X and Y values to add successive page elements. Also please note that it is not possible to set the X and Y for the AreaGroup page element. You can refer to the documentation on AreaGroup class here
.
Regarding ContentArea, you can add multiple page elements to it by specifying the X and Y positions. You can change the X, Y positions of the ContentArea page element and this will move all the contents in ContentArea to new specified positions accordingly. Please note that you will need to set the correct calculated height for the ContentArea. Then you can compare the ContentArea height with available space in the page and decide on adding it to the current page or move it to next page. Below is the code sample for it.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
string text = "This is to test ";
for (int i = 0; i < 8; i++)
{
text = text + text;
}
TextArea textAreaObj = new TextArea(text, 0, 0, 400, 500);
textAreaObj.Height = textAreaObj.GetRequiredHeight();
page.Elements.Add(textAreaObj);
float availableSpaceOnPage = page.Dimensions.Body.Height - (textAreaObj.Y + textAreaObj.Height);
//Build ContentArea by adding page elements.
ContentArea groupObj = new ContentArea(0, 0, 100, 100);
TextArea area1 = new TextArea("This is text in TextArea1 to test the AreaGroup", 0, 0, 200, 10);
area1.Height = area1.GetRequiredHeight();
groupObj.Add(area1);
float newYPosition = area1.Y + area1.Height + 3;
TextArea area2 = new TextArea("This is text in TextArea2 to test the AreaGroup", 0, newYPosition, 200, 10);
area2.Height = area2.GetRequiredHeight();
groupObj.Add(area2);
groupObj.Height = area2.Y + area2.Height + 3;
if (groupObj.Height < availableSpaceOnPage)
{
page.Elements.Add(groupObj);
}
else
{
page = new Page();
document.Pages.Add(page);
groupObj.X = 0;
groupObj.Y = 0;
page.Elements.Add(groupObj);
}
document.Draw(@"C:\Temp\Output.pdf");
Thanks,
ceTe Software Support Team.