How to detect table overlaps the page footer for Word document using .NET

hello team,
I have a problem of how to check the page cross the border of current document page, e.g. run, paragraph, picture,table etc. the below is example document
printout5.zip (87.9 KB)

@TommyZhou

To get the border of page, please use PageSetup.Borders property. For paragraph, you can use Paragraph.ParagraphFormat.Borders property.

In your document, the text is inside table. You can get the border of table using CellFormat.Borders property. We suggest you please read the following articles.
Applying Borders and Shading
Applying Borders and Shading to a Paragraph

Hope this answers your query. Please let us know if you have any more queries.

Thanks for your reply,
but I may not have made myself clear, i want to detect the page content whether completely within page, e.g. image.png (6.5 KB)

instead of this, e.g.image.png (6.8 KB)

or image.jpg (104.4 KB)

how to detect with the Aspose API, pls attach the sample code , thanks a lot,

the completely document printout5.zip (87.9 KB)

@TommyZhou

In your case, you need to use the layout API to get the position of last node of table. You can compare this position with footer position. Following code example shows how to check table’s start and end position. Moreover, it shows how to check if table is overlapped the footer. Hope this helps you.

Document document = new Document(MyDir + "printout5.docx");
DocumentBuilder builder = new DocumentBuilder(document);
                
//Get the table
Table table = (Table)document.Range.Bookmarks["PaperSectionEnd1"].BookmarkStart.GetAncestor(NodeType.Table);

//insert the bookmark in the last cell of table.
builder.MoveTo(table.LastRow.LastCell.LastChild);
builder.StartBookmark("bookmark");
builder.EndBookmark("bookmark");

Bookmark bm = document.Range.Bookmarks["bookmark"];
document.UpdatePageLayout();

//Get the position of table's last cell
LayoutCollector layoutCollector = new LayoutCollector(document);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(document);

Console.WriteLine(layoutCollector.GetStartPageIndex(table) + "--" + layoutCollector.GetEndPageIndex(table));

layoutEnumerator.Current = layoutCollector.GetEntity(bm.BookmarkStart);
Console.WriteLine(" --> Left : " + layoutEnumerator.Rectangle.Left + " Top : " + layoutEnumerator.Rectangle.Top);

//Get the position of table's footer. 
PageSetup ps = ((Section)table.GetAncestor(NodeType.Section)).PageSetup;
double footer = ps.PageHeight - ps.HeaderDistance;
if (layoutEnumerator.Rectangle.Top > footer)
    Console.WriteLine("Table is overlapped the footer of page.");

Thank you much for your reply, i have a another question about how to detect the table is overlap the document left or right margin, the table or row may be not set the preferred with, filled with the internal content, just like the big picture or internal table etc.
overlap.zip (62.5 KB)

Looking forward your reply, thk.

@TommyZhou

You can check width of image and table’s cell to achieve your requirement. Please check the following code snippet. Hope this helps you.

Document doc = new Document(MyDir + "overlap.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Cell cell = (Cell)shape.GetAncestor(NodeType.Cell);
Console.WriteLine(shape.Width);
Console.WriteLine(cell.CellFormat.Width);