The problem is probably that I have an odd number of rows in my table. My table consist of a header row followed by items , in pair of two rows.
So I want to keep the pair of two rows together on a page. Therefore I've set my KeepWith=2 on the first row AFTER the header row. However, since this is in a loop, the KeepWith is being set on each new pair of two rows...
Code:
table = section.AddTable();
table.Rows.LeftIndent = 0;
var column = table.AddColumn("13cm");
column = table.AddColumn("1.5cm");
column = table.AddColumn("2.5cm");
column = table.AddColumn("2.5cm");
// Create the header of the table.
var row = table.AddRow();
row.HeadingFormat = true; // repeat on each page
row.Borders.Bottom.Width = 0.25;
row.Cells[0].AddParagraph("Artikelomschrijving");
row.Cells[1].AddParagraph("Aantal");
row.Cells[2].AddParagraph("Artikelprijs");
row.Cells[3].AddParagraph("Arbeidsloon");
foreach (DocumentDetailModel item in _doc.DocumentDetails)
{
// first row of 2
row = table.AddRow();
row.KeepWith = 2;
row.Cells[0].AddParagraph(item.Artikelomschrijving);
row.Cells[1].AddParagraph(item.Aantal.ToString());
row.Cells[2].AddParagraph($"{(item.Artikelprijs * item.Aantal).ToString("0.00")} €");
row.Cells[3].AddParagraph($"{item.Arbeidsloon.ToString("0.00")} €");
// second row
row = table.AddRow();
if (item.Artikelomschrijvingdetail!=null && item.Artikelomschrijvingdetail.Trim()!=String.Empty)
{
row.Cells[0].AddParagraph(item.Artikelomschrijvingdetail);
}
}