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);
}