Hi,
I have a static table with 4 rows and 3 columns with static information on the page I have created.
Now i want to add another table that is populated dynamically using loop. When i use overflow method like in documentation. it prints the rows starting from the new page, while i have almost half page which is empty on previous created/added page in document. How to use the remaining space of the page and then create the new page and so on. ???? My code is given below:
Document document = new Document();
// Create a page
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.A4);
document.Pages.Add(page);
Table2 table = new Table2(0, 0, 700, 100);
//table.CellDefault.Border.Color = RgbColor.White;
table.Border.LineStyle = LineStyle.None;
table.CellSpacing = 1.0f;
// Add columns to the table
table.Columns.Add(100);
table.Columns.Add(200);
table.Columns.Add(100);
table.Columns.Add(100);
// Add rows to the table and add cells to the rows
Row2 row1 = table.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
row1.CellDefault.Align = ceTe.DynamicPDF.TextAlign.Center;
row1.CellDefault.VAlign = VAlign.Center;
row1.CellDefault.Border.LineStyle = LineStyle.None;
row1.Cells.Add("Client Name :").Align = ceTe.DynamicPDF.TextAlign.Left;
row1.Cells.Add("Mike Trevor").Align = ceTe.DynamicPDF.TextAlign.Left;
row1.Cells.Add("Ref :").Align = ceTe.DynamicPDF.TextAlign.Right;
row1.Cells.Add("MH24050039-1").Align = ceTe.DynamicPDF.TextAlign.Right;
// Add rows to the table and add cells to the rows
Row2 row2 = table.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
row2.CellDefault.Align = ceTe.DynamicPDF.TextAlign.Center;
row2.CellDefault.Border.LineStyle = LineStyle.None;
row2.Cells.Add("Postal Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
row2.Cells.Add("1234567890,ABC,ABC,54000 ").Align = ceTe.DynamicPDF.TextAlign.Left;
row2.Cells.Add("Date :").Align = ceTe.DynamicPDF.TextAlign.Right;
row2.Cells.Add("12 May 2024").Align = ceTe.DynamicPDF.TextAlign.Right;
// Add rows to the table and add cells to the rows
Row2 row3 = table.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
row3.CellDefault.Border.LineStyle = LineStyle.None;
row3.CellDefault.Align = ceTe.DynamicPDF.TextAlign.Center;
row3.Cells.Add("Mobile No :").Align = ceTe.DynamicPDF.TextAlign.Left;
row3.Cells.Add("03214787567").Align = ceTe.DynamicPDF.TextAlign.Left;
// Add rows to the table and add cells to the rows
Row2 row4 = table.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
row4.CellDefault.Border.LineStyle = LineStyle.None;
row4.CellDefault.Align = ceTe.DynamicPDF.TextAlign.Center;
row4.Cells.Add("Email :").Align = ceTe.DynamicPDF.TextAlign.Left;
row4.Cells.Add("awaisahmad042@gmail.com").Align = ceTe.DynamicPDF.TextAlign.Left;
// Add rows to the table and add cells to the rows
Row2 row5 = table.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
row5.CellDefault.Border.LineStyle = LineStyle.None;
row5.CellDefault.Align = ceTe.DynamicPDF.TextAlign.Center;
row5.Cells.Add("Site Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
row5.Cells.Add("N/A").Align = ceTe.DynamicPDF.TextAlign.Left;
page.Elements.Add(table);
-- Adding another table for dynamic size data by loop.
// Add a new table for dynamic rows
Table2 dynamicTable = new Table2(0, table.Height + 20, 500, 1000);
dynamicTable.Border.LineStyle = LineStyle.Solid;
// Add columns to the dynamic table
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(200);
// Populate dynamic table with rows
for (int i = 1; i <= 50; i++)
{
Row2 dynamicRow = dynamicTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White);
dynamicRow.Cells.Add($"Data {i}");
dynamicRow.Cells.Add($"Data {i}");
dynamicRow.Cells.Add($"Data {i}");
}
// Add the dynamic table to the page
page.Elements.Add(dynamicTable);
The above code is overflowing the data , if i use the overflow method like below with the above code:
do
{
Page page = new Page();
document.Pages.Add(page);
page.Elements.Add(table);
table = table.GetOverflowRows();
} while (table != null);
It is not working fine.
(The thing is that i will set the logic for the visibility of controls like i want to hide and show some tables or elements on the page from database control ,,,,, ), SO thi dynamic page is either not working or when working it is not using the remaining previous page........
Can u please help me .
Thanks.