We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Order of headerFooter nodes

Hi,
I am using Aspose Words for java.I have a document with two sections having header in both. I am taking the header nodes from the document using the code

NodeCollection headFootNodes = doc.getChildNodes(NodeType.HEADER_FOOTER, true);
for (int hfCount = 0; hfCount < headFootNodes.getCount(); hfCount++) {
HeaderFooter headFoot = (HeaderFooter) headFootNodes.get(hfCount);
if (headFoot.getStoryType() == StoryType.PRIMARY_HEADER || headFoot.getStoryType() == StoryType.EVEN_PAGES_HEADER || headFoot.getStoryType() == StoryType.FIRST_PAGE_HEADER) { System.out.println(headFoot.getStoryType());
}//if
}//for

I am getting the second section’s header as first node and first sections header as second.Is this usual? I need to process the headers in order(firstpage->even_page).How to do that?

Hi

Thanks for your request. I think, in your case you can use code like the following:

// Open document.

Document doc = new Document("in.doc");

// Loop through section in the document.

for(Section sect : doc.getSections())

{

// Process HeaderFooter nodes in order you need.

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_FIRST)!=null)

{

// Process first page header.

}

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_EVEN)!=null)

{

// Process even page header.

}

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY)!=null)

{

// Process primary page header.

}

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_FIRST)!=null)

{

// Process first page footer.

}

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN)!=null)

{

// Process even page footer.

}

if(sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY)!=null)

{

// Process primary page footer.

}

}

Hope this helps.

Best regards,