Good morning,
I’m trying to define the cell splitting behavior in such a way that, when a row contains one or more cells that are too tall to fit entirely on the current page, the row doesn’t get moved entirely to the next page.
I know that cell splitting is possible, as it occurs when the row height exceeds the page height. So, is there a way to prevent the resulting white space and allow partial row rendering across pages?
I’ve attached a code sample that can be run in LINQPad.
Thanks in advance!
class Program
{
static void Main()
{
Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
Table table = new Table
{
ColumnWidths = "100 100 100",
DefaultCellBorder = new BorderInfo(BorderSide.All, 0.5f),
DefaultCellTextState = new TextState { FontSize = 12 },
RepeatingRowsCount = 1,
};
Row headerRow = table.Rows.Add();
headerRow.Cells.Add("Name");
headerRow.Cells.Add("Age");
headerRow.Cells.Add("Country");
var longDesc = "antami, o Diva, del pelide Achille l'ira funesta che infiniti addusse lutti agli Achei, molte anzi tempo all'Orco generose travolse alme d'eroi, e di cani e d'augelli orrido pasto lor salme abbandonò (così di Giove l'alto consiglio s'adempìa), da quando primamente disgiunse aspra contesa il re de' prodi Atride e il divo Achille. E qual de numi inimicolli? Il figlio di Latona e di Giove. Irato al Sire destò quel Dio nel campo un feral morbo, e la gente perìa: colpa d'Atride, che fece a Crise sacerdote, oltraggio.";
string[,] data = {
{ "Alice", "21", "USA" },
{ "Bob", "321", "UK" },
{ "Charlie", longDesc, "Canada" },
{ "Diana", longDesc, "Italy" }
};
for (int i = 0; i < data.GetLength(0); i++)
{
Row row = table.Rows.Add();
for (int j = 0; j < data.GetLength(1); j++)
{
var stuff = new TextFragment(data[i, j]);
var c = row.Cells.Add();
c.Paragraphs.Add(stuff);
}
}
page.Paragraphs.Add(table);
pdfDocument.Save("C:\\TestPDF.pdf");
}
}
//in the generated pdf there is a white space at the end of the first page, that is avoidable if the cell split