Problems getting table height for new table on existing PDF

I am trying to add a table to an already existing PDF. The table must be constrained to a fixed known size on the page. It will consist of multiple rows of unknown content. If the table exceeds the constrained size, it will be continued on the next page, however the location on that page may be different and may have different constraints.


My thought was to build the table adding new rows individually, and then check the table height. If the table with the added row exceeded the maximum constraint size, remove the last row, and move to the next page to continue.

The problem I have encountered, is that when I call Table.GetHeight() it returns a rather large number. 2147482877.0 to be precise.

For the following code snippet to demonstrate the issue, assume that the table needs to be placed in an area 2 inches wide and 4 inches tall with an upper left corner at (1", 1") with columns that are 1" wide. The rows I am using for this sample are fixed, but we cannot assume that will be the case for the actual use case. You should also assume that Aspose has been licensed outside this function.

using (FileStream output = new FileStream(@".\Output3.pdf", FileMode.Create, FileAccess.Write))
{
Document doc = new Document();
Page newPage = doc.Pages.Add();
newPage.PageInfo.Margin.Bottom = 0;
newPage.PageInfo.Margin.Top = 0;
newPage.PageInfo.Margin.Left = 0;
newPage.PageInfo.Margin.Right = 0;

Table newTable = new Table();
newTable.Left = 72;
newTable.Top = 72;
newTable.BackgroundColor = Color.DarkGreen;
newTable.ColumnWidths = 72.ToString() + " " + (72).ToString();

while (newTable.GetHeight() < 288)
{
Row newRow = newTable.Rows.Add();
newRow.Cells.Add(“Column1\r\nSecondRow\r\nThirdRow”);
newRow.Cells.Add(“Column2\r\nSecondRow”);
}
double tableHeight = newTable.GetHeight();

doc.Save(output);
}


jay.johns:
Any ideas?
Hi,

Thanks for using our API's.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNET-41518 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Has this been fixed yet? I have exactly the same problem.

Hi Norman,


Thanks for contacting support.

I am afraid the earlier reported issue is not yet resolved, as the team has been busy fixing other previously reported issues. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

I think I may have found the solution (it worked for me).


The problem for me was these two lines:
newTable.Left = 72;
newTable.Top = 72;

I removed those and instead used the Margin feature and positioned the table by setting Margin.Top = 72.

That caused the getHeight function to start working and return a valid value instead off of the huge number.

mike11:
I think I may have found the solution (it worked for me).

The problem for me was these two lines:
newTable.Left = 72;
newTable.Top = 72;

I removed those and instead used the Margin feature and positioned the table by setting Margin.Top = 72.

That caused the getHeight function to start working and return a valid value instead off of the huge number.

Hi Mike,

Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel free to contact.