Aspose Words Determine if a doc has pagenumber

Hai,
I wanted to know if there is any way to check whether a document has pagenumber defined in header or footer section programatically using aspose.

@pooja.jayan Sure you can achieve this. You can check whether header/footer nodes contain PAGE fields. For example see the following code:

private static bool HeaderFooterHasPage(Document doc)
{
    NodeCollection headerFooters = doc.GetChildNodes(NodeType.HeaderFooter, true);
    foreach (HeaderFooter hf in headerFooters)
    {
        foreach (Field f in hf.Range.Fields)
            if (f.Start.FieldType == FieldType.FieldPage)
                return true;
    }
    return false;
}

Hai,
It worked! and thank you so much for your quick response.

1 Like