Copy All Headers and Footer from one section to another section

Hi guys,

Is there any way to copy all the headers and footers from the first section to the last section of the document?

Kind regards,
Paulo Pereira

I’m using the lastest version of Aspose words JAVA

@pamp You can use code like the following to achieve this:

// If there are more than one section.
if (doc.getSections().getCount() > 1)
{
    // Remove headers footer from the last section.
    doc.getLastSection().getHeadersFooters().clear();
    // If the last section is the next section after the first one,
    // it is not required to copy headers footers, removing them will make
    // headers footer linked to the previous section.
    if (doc.getSections().getCount() > 2)
    {
        for (HeaderFooter hf : doc.getFirstSection().getHeadersFooters())
        {
            doc.getLastSection().getHeadersFooters().add(hf.deepClone(true));
        }
    }
}

Hi @alexey.noskov, Thank you for the feedback, it was helpful.

Kind regards,
Paulo Pereira