Dynamic width for the outer table of nested tables based on page break

Hello Aspose forum,

We are using full Aspose.Total license.

Query: We have a nested table with outer table having two columns with 33% and 66% width. The inside table in the 2nd column is dynamic in nature. We want the outer table columns to modify to 0% and 100% width respectively once the dynamic table finishes rendering content in first page and moves onto the next page.

eg:
aspose query.docx (28.9 KB)

In the above aspose query document doc, we can see that its having nested tables. The first column contains generic table and a chart and second column contains 2 dynamic tables. What we want to achieve is that once the page breaks from second page the outer table’s 2nd column must occupy the 100 percent width of the page since we dont want to waste the empty space in second page. i.e from the row containing “Deferred gold silver” we want that table entries to occupy 100 % width. Could you please let us know if there is a way to achieve this via Aspose.Words. We also want this to be achieved in pdf too. We usually generate a doc from Aspose.words and then save it as pdf for the pdf version.

@sbaskar1 I am afraid it is not possible to implement this using nested tables. However, in your case you can use section with two columns. In this case it is possible to determine where the table flows to the next page and split the table. Please see the modified document: in.docx (30.7 KB)
Here is the code to split the table and put the second part of the table into the section with one column:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);

// Get number of pages in the document.
int pages = doc.PageCount;
if (pages > 1)
{
    Table table = null;
    // Search the table that break spans the second page.
    foreach(Table t in doc.FirstSection.Body.Tables)
    {
        if (collector.GetStartPageIndex(t) != collector.GetEndPageIndex(t))
        {
            table = t;
            break;
        }
    }

    if (table != null)
    {
        // Create a section with one column to move the part of table that goes to the next page.
        Section sect = new Section(doc);
        sect.EnsureMinimum();
        sect.Body.RemoveAllChildren();
        doc.AppendChild(sect);

        // Copy all nodes after the table into the next section.
        while (table.NextSibling != null)
            sect.Body.AppendChild(table.NextSibling);

        // Clone the original table.
        Table nextPageTable = (Table)table.Clone(false);

        // Copy all rows that goes to the next page.
        int rowIndex = 0;
        int pageIndex = collector.GetStartPageIndex(table);
        foreach (Row r in table.Rows)
        {
            if (collector.GetStartPageIndex(r) > pageIndex)
            {
                rowIndex = table.IndexOf(r);
                break;
            }
        }

        while (table.Rows.Count > rowIndex)
            nextPageTable.PrependChild(table.LastRow);

        sect.Body.PrependChild(nextPageTable);
    }
}

doc.Save(@"C:\Temp\out.docx");

Here are output document: out.docx (25.4 KB)