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

Free Support Forum - aspose.com

Need to Remove Footer and Header section

Dear team,

I need to remove Footer and Header section from docx im using below source code, Please help me on below case

for (Section section : doc.getSections())
{
	header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_FIRST);
	footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_FIRST);
	if (header != null)
		header.remove();
	if (footer != null)
		footer.remove();
	header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_EVEN);
	footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN);
	if (header != null)
		header.remove();
	if (footer != null)
		footer.remove();
}

doc.save(AIE.interim);

Input File : Experimental studies on compressive-CBM-0618 - clean -2.docx (2.8 MB)

@e503824 Please consider the following code.

for (Section section : doc.getSections())
{
    HeaderFooter[] headersFooters = section.getHeadersFooters().toArray();
    for (HeaderFooter headerFooter : headersFooters)
        headerFooter.remove()

}

Thanks now it’s working fine

1 Like