Insert row on start when table split across to the next page

hello,
i am trying to track a page break , means i have a table split across on pages , i want when page ends and rows start render on 2 page i want to add a new row and custom columns before 1st row of the 2nd page or 3rd page … am confuse how can i get the index of first row of second page and insert new row before it.

@bilalkhan190 Literally, it can be like this.

Document doc = new Document("TestDoc.docx");

LayoutCollector lc = new LayoutCollector(doc);
Table table = doc.FirstSection.Body.Tables[0];

Row rowToInsert = table.FirstRow.Clone(true) as Row;
foreach (Cell cell in rowToInsert.Cells)
    cell.FirstParagraph.FirstRun.Text = "2";


foreach (Row row in table.Rows)
{
    if (lc.GetStartPageIndex(row) == 2)
    {
        table.InsertBefore(rowToInsert, row);
        break;
    }
}

doc.Save("TestDoc_out.docx");

TestDoc.docx (18.6 KB)

Or may be you just want a header row that repeats on every page?

yes i want header row to be attached when page breaks … thank you for assistance

@bilalkhan190 Please feel free to ask in case of any issues, we will be glad to help you.

@bilalkhan190 You may also find it useful to have the possibility to set the first row as the header row. In this case, it will be repeated on every page.

table.FirstRow.FirstCell.FirstParagraph.FirstRun.Text = "Header Row";
table.FirstRow.RowFormat.HeadingFormat = true; 

Thank you for your help really appreciated, problem solved :smiley: