Hey there,
It sounds like you're having trouble with table rows overflowing to a new page without using the remaining space on the current page.To fix this, you need to calculate the remaining space on the current page and add rows to the dynamic table until the page is full. Here’s a simplified version of your code to help with that:
Document document = new Document();
// Create the first page and add the static table
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.A4);
document.Pages.Add(page);
Table2 staticTable = new Table2(0, 0, 700, 100);
staticTable.Columns.Add(100);
staticTable.Columns.Add(200);
staticTable.Columns.Add(100);
staticTable.Columns.Add(100);
// Add rows to the static table
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Client Name :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Postal Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Mobile No :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Email :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Site Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
page.Elements.Add(staticTable);
// Calculate remaining height on the page
float remainingHeight = PageSize.A4.Height - staticTable.Y - staticTable.Height;
// Add dynamic table
Table2 dynamicTable = new Table2(0, staticTable.Y + staticTable.Height + 20, 500, remainingHeight);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(200);
int rowHeight = 20;
int rowsPerPage = (int)(remainingHeight / rowHeight);
// Populate dynamic table
for (int i = 1; i <= 50; i++) {
if ((i - 1) % rowsPerPage == 0 && i != 1) {
// Add dynamic table to page and create a new page if full
page.Elements.Add(dynamicTable);
page = new Page(PageSize.A4);
document.Pages.Add(page);
dynamicTable = new Table2(0, 0, 500, 1000);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(200);
}
dynamicTable.Rows.Add(rowHeight, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add($"Data {i}");
}
// Add the final dynamic table to the page
page.Elements.Add(dynamicTable);
// Save the document
document.Draw("[path to save document]");
Sure, here's a simplified response:
Hi there,
Thanks for reaching out. It sounds like you're having trouble with table rows overflowing to a new page without using the remaining space on the current page.
To fix this, you need to calculate the remaining space on the current page and add rows to the dynamic table until the page is full. Here’s a simplified version of your code to help with that:
csharp
Copy code
Document document = new Document();
// Create the first page and add the static table
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.A4);
document.Pages.Add(page);
Table2 staticTable = new Table2(0, 0, 700, 100);
staticTable.Columns.Add(100);
staticTable.Columns.Add(200);
staticTable.Columns.Add(100);
staticTable.Columns.Add(100);
// Add rows to the static table
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Client Name :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Postal Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Mobile No :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Email :").Align = ceTe.DynamicPDF.TextAlign.Left;
staticTable.Rows.Add(20, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add("Site Address :").Align = ceTe.DynamicPDF.TextAlign.Left;
page.Elements.Add(staticTable);
// Calculate remaining height on the page
float remainingHeight = PageSize.A4.Height - staticTable.Y - staticTable.Height;
// Add dynamic table
Table2 dynamicTable = new Table2(0, staticTable.Y + staticTable.Height + 20, 500, remainingHeight);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(200);
int rowHeight = 20;
int rowsPerPage = (int)(remainingHeight / rowHeight);
// Populate dynamic table
for (int i = 1; i <= 50; i++) {
if ((i - 1) % rowsPerPage == 0 && i != 1) {
// Add dynamic table to page and create a new page if full
page.Elements.Add(dynamicTable);
page = new Page(PageSize.A4);
document.Pages.Add(page);
dynamicTable = new Table2(0, 0, 500, 1000);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(100);
dynamicTable.Columns.Add(200);
}
dynamicTable.Rows.Add(rowHeight, Font.Helvetica, 9, RgbColor.Black, RgbColor.White).Cells.Add($"Data {i}");
}
// Add the final dynamic table to the page
page.Elements.Add(dynamicTable);
// Save the document
document.Draw("[path to save document]");
This code ensures that the remaining space on the first page is used before moving to a new page. Hope it helps!!