Aspose.Words Java Unable to get all the Header and Footer Information through transversal of Nodes

Currently we were splitting word documents into to pages by using getPageCount() and extractPage…(). This method takes much too long as it has to render the document to figure the page count. We then attempted to gather all the header and footer information by transversal of the nodes of the document. We are able to get the body and the primary header but the additional pages that have different header and footer we are not able to gather going through the nodes as we were able to by getting the sections after we extracted pages into their own document. Any information on this would be helpful thanks in advance.WI418814.zip (84.8 KB)

@dmckinney,

The following Java code will print what types of headers and footers are actually available in each of your Word documents that you shared:

String path = "C:\\Temp\\WI418814\\";
String pattern = "*.doc?";

String[] fileNames = GetFiles(path, pattern);
for (String fileName : fileNames) {
    Document doc = new Document(path + fileName);
    System.out.println(doc.getOriginalFileName());

    int sectionIdx = 0;
    for (Section section : doc.getSections()) {
        System.out.println("    Section " + sectionIdx + " has following headers footers");
        for (HeaderFooter headerFooter : section.getHeadersFooters()) {
            System.out.println("        " + HeaderFooterType.getName(headerFooter.getHeaderFooterType()));
        }
        sectionIdx++;
    }
    System.out.println("------------------------");
}

public static String[] GetFiles(final String path, final String searchPattern) {
    final Pattern re = Pattern.compile(searchPattern.replace("*", ".*").replace("?", ".?"));
    return new File(path).list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return new File(dir, name).isFile() && re.matcher(name).matches();
        }
    });
}

MSWordFile.docx and sandeep_resume.doc have all six types of Headers and Footers but only their Primary Headers and Footers contain content (others are empty).

You may also want to take a look at the following properties: