Get height of footer

Hi team,
Is there any progress on getting the height of document footer?
Is there any way to support it?

@TobyLiu

You can use the Aspose.Words.Layout API to get the height of header and footer. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

MarkHeaderFooterBoundaries(enumerator);

public static void MarkHeaderFooterBoundaries(LayoutEnumerator enumerator)
{
    do
    {
        if (enumerator.MoveLastChild())
        {
            MarkHeaderFooterBoundaries(enumerator);
            enumerator.MoveParent();
        }

        if (enumerator.Type == LayoutEntityType.HeaderFooter)
        {
            double height = GetHeight(enumerator);
            Console.WriteLine(height);
        }

        // Stop after all elements on the page have been procesed.
        if (enumerator.Type == LayoutEntityType.Page)
            return;

    } while (enumerator.MovePrevious());
}

public static double GetHeight(LayoutEnumerator enumerator)
{
    double top = 0;
    DocumentBuilder builder = new
    DocumentBuilder(enumerator.Document);

    if (enumerator.Kind.Equals("FIRSTPAGEFOOTER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
        top = enumerator.Rectangle.Top;
    }
    else if (enumerator.Kind.Equals("PRIMARYFOOTER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
        top = enumerator.Rectangle.Top;
    }
    else if (enumerator.Kind.Equals("EVENPAGESFOOTER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
        top = enumerator.Rectangle.Top;
    }
    else if (enumerator.Kind.Equals("FIRSTPAGEHEADER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
        top = enumerator.Rectangle.Top + enumerator.Rectangle.Height;
    }
    else if (enumerator.Kind.Equals("PRIMARYHEADER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
        top = enumerator.Rectangle.Top + enumerator.Rectangle.Height;
    }
    else if (enumerator.Kind.Equals("EVENPAGESHEADER"))
    {
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
        top = enumerator.Rectangle.Top + enumerator.Rectangle.Height;
    }

    return top;
}

@tahir.manzoor
I used the method you gave to get the height of the header footer. So far, there is no problem with the height of the header, but the height value of the footer is still not accurate. Is there any special code to handle the footer part?

Attached is the document I want to get the footer height.paper 2_Version 1 (2).zip (101.0 KB)

@TobyLiu

LayoutEnumerator.Rectangle property returns the bounding rectangle of the current entity relative to the page top left corner (in points). You need to subtract the page height from Rectangle.Top as shown below. Hope this helps you.

else if (enumerator.Kind.Equals("PRIMARYFOOTER"))
{
    builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
    top = builder.CurrentSection.PageSetup.PageHeight - enumerator.Rectangle.Top
        - builder.CurrentSection.PageSetup.HeaderDistance;
}