We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Words (.NET) - Tables with page breaks problem

Hello.

I want to build two tables, and each table should begin on new page. Example code:

    asposeBuilder.StartTable();

    for (int y = 0; y < 10; y++)
    {
        for (int x = 0; x < 5; x++)
        {
            asposeBuilder.InsertCell();
            asposeBuilder.Write($"x: {x} y: {y}");
        }

        asposeBuilder.EndRow();
    }

    asposeBuilder.EndTable();

    asposeBuilder.InsertBreak(BreakType.PageBreak);

    asposeBuilder.StartTable();

    for (int y = 0; y < 10; y++)
    {
        for (int x = 0; x < 5; x++)
        {
            asposeBuilder.InsertCell();
            asposeBuilder.Write($"x: {x} y: {y}");
        }

        asposeBuilder.EndRow();
    }

    asposeBuilder.EndTable();

The problem is that there is empty paragraph before second table, using the code above. Here is screenshot that demonstrates the problem: Screenshot 2021-09-14 182505.png (32.4 KB)

actual result.docx (7.5 KB)
expected result.docx (7.8 KB)

Is there any workaround for this issue?

@buryginl

Please use ParagraphFormat.PageBreakBefore property as shown below to get the desired output.

Document document = new Document();
DocumentBuilder asposeBuilder = new DocumentBuilder(document);
asposeBuilder.StartTable();

for (int y = 0; y < 10; y++)
{
    for (int x = 0; x < 5; x++)
    {
        asposeBuilder.InsertCell();
        asposeBuilder.Write($"x: {x} y: {y}");
    }

    asposeBuilder.EndRow();
}

asposeBuilder.EndTable();


Table table = asposeBuilder.StartTable();
               
for (int y = 0; y < 10; y++)
{
    for (int x = 0; x < 5; x++)
    {
        asposeBuilder.InsertCell();
        asposeBuilder.Write($"x: {x} y: {y}");
    }

    asposeBuilder.EndRow();
}

asposeBuilder.EndTable();

table.FirstRow.FirstCell.FirstParagraph.ParagraphFormat.PageBreakBefore = true;

document.Save(MyDir + @"out 21.9.docx");