Possibility to make a table fill the entire page

Hello,

i have a question concerning tables in Word (and the possible way of doing this with Aspose words):

Let’s say I have a Table with a header, 4 lines of data and a footer. Is it possible to fit this to the entire (remaining) page, so that there will be the header, 4 lines of data, a to-me-unknown number of blank lines and the footer on the page?

so let’s say we have

---- page start----
randomtext
tableheader
line1
line2
line3
line4
tablefooter

— page end

and we would like to have

---- page start----
randomtext
tableheader
line1
line2
line3
line4
(empty filler line)
(empty filler line)
(empty filler line)
(empty filler line)
tablefooter
— page end

Is that possible?

Best regards,
Scherge

Hi Scherge,

Thanks for your inquiry. Could you please attach your input and expected output Word documents here for our reference? We will then provide you more information about your query along with code.

Please find attached the input (before) and output (after) documents

Hi Scherge,

Thanks for sharing the detail. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages. LayoutCollector.GetStartPageIndex method gets 1-based index of the page where node begins.

We suggest you please keep inserting the empty paragraph in the desired row and keep checking the page number of last row of table until page number of last row is changed. Please check following code example for your kind reference. Hope this helps you.

Document doc = new Document(MyDir + "Before.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
LayoutCollector collector = new LayoutCollector(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
Row lastrow = table.Rows[2];
Row row2 = table.Rows[1];
int page = collector.GetStartPageIndex(lastrow);
while (true)
{
    collector = new LayoutCollector(doc);
    builder.MoveTo(row2.LastCell.LastChild);
    builder.ParagraphFormat.ClearFormatting();
    builder.InsertParagraph();
    if (collector.GetStartPageIndex(lastrow) == page + 1)
    {
        row2.LastCell.LastChild.Remove();
        break;
    }
}
row2.LastCell.LastChild.Remove();
doc.Save(MyDir + "Out.docx");