Table header split issues

Hello.

In my document I have text and a table. The table should go after the text. Here there are rules that should be obeyed:
1) The table should be split across multiple pages if it cannot be placed in 1 page;
2) The table should be placed directly after the text if it’s possible to display 1 content row at least (1 header row + 1 content row) on a page;
3) It should not be the header row only on the page, in this case it should be moved to the next page.

I attached the sample project for your reference.
Here there are the code snippet from the sample:
for (int i = 0; i < 64; i++)
{
textContent.AppendLine("line " + i.ToString());
}
The rule 2 can be simulated when i == 40;
The rule 3 can be simulated when i == 64;

My problem is that I cannot implement rules 2 and 3 work simultaneously, because when I set table.IsBroken = false the rule 2 does not work, because the entire table is moved to the next page even if it’s enough space to place 2+ content rows.
If I do not set table.IsBroken the rule 3 may not work (when i == 64) because the only one header row remains on the first page.

In other words I need the behavior when the 1st (the header) and the 2nd (the first content) rows are kept together and can be displayed on the page if it’s enough space for them both.

Could you please advise how to implement the required behavior.

Hi Dmitry,

Thanks for your inquiry. Please note you are using old approach for creating PDF document. Please use new DOM approach (new generator) for the purpose, it will resolve the issue. It can be used for both creating a PDF document from scratch or to manipulate existing PDF. It is more efficient and improved. Please check sample code snippet for the purpose.

Document document = new Document();

Aspose.Pdf.Page docSection = document.Pages.Add();

docSection.PageInfo.Margin = new Aspose.Pdf.MarginInfo
{ Bottom = 0, Left = 0, Right = 0, Top = 0 };

// add fake text

for (int i = 0; i < 81; i++)
{
    TextFragment textPar = new TextFragment("line " + i.ToString());

    docSection.Paragraphs.Add(textPar);
}

docSection.Paragraphs.Add(new TextFragment("")); // empty line separates topics

// add sample table

DataTable dataSource = GenerateSampleTable();

Table table = new Table
{
    DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F),
    DefaultColumnWidth = "150",
    RepeatingRowsCount = 1,
    Margin = { Top = 2, Bottom = 0 }
};

float colWidth = 150;

MarginInfo headerPadding = new MarginInfo { Left = 5, Top = 5, Right = 5, Bottom = 5 };
MarginInfo contentPadding = new MarginInfo { Left = 2, Top = 2, Right = 2, Bottom = 2 };

Row headerRow = table.Rows.Add();

foreach (DataColumn dc in dataSource.Columns)
{
    Cell cell = headerRow.Cells.Add(dc.ColumnName);
    cell.BackgroundColor = Aspose.Pdf.Color.Yellow;
}

foreach (DataRow sourceRow in dataSource.Rows)
{
    Row destRow = table.Rows.Add();

    foreach (DataColumn dc in dataSource.Columns)
    {
        Cell cell = destRow.Cells.Add(sourceRow[dc].ToString());
    }
}

docSection.Paragraphs.Add(table);

document.Save("Tableoutput1.pdf");

Please feel free to contact us for any further assistance.

Best Regards,

Hello,


Thanks for you response. In which version the new approach was implemented?We’re using v. 7.7.0.0. because of our license subscription.

Hi Dmitry,


Thanks for your feedback. New DOM approach was introduced in 6.0.0. However we have made number of fixes, enhancements and features in next releases. So it is recommend to used latest version of Aspose.Pdf for .NET i.e. 10.5.0.

Best Regards,

Hello,


I could not find how to set the text as “StrikeOut”. I can set this property to TextInfo instance from Aspose.Pdf.Generator (old approach), but cannot do the same with the recommended TextFragment (new approach).

Please advise.

Hi Dmitry,

Thanks for your inquiry. I am afraid the strikeout feature is missing in TextFragment, we have already logged a ticket PDFNEWNET-38556 for the rectification. We will notify you as soon as it is resolved. However, as a workaround, you can use HtmlFragment for adding html text for the purpose as following.

HtmlFragment html = new HtmlFragment("<p>Aspose.Pdf for .NET 10.6.0 is <strike>not yet available!</strike> now available!</p>");
page.Paragraphs.Add(html);

We are sorry for the inconvenience caused.

Best Regards,