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

Free Support Forum - aspose.com

Is it possible to remove the Footer alone and retain the Header

Team,
We are using Aspose.Word (for Java).

I am using the following code to remove the Header and the Footer.

Document doc = new Document(oInputStream);
for (int i = 0; i < doc.getSections().getCount(); i++)
{
doc.getSections().get(i).getHeadersFooters().clear();
}

Is it possible to remove only the Footer and retain the Header. If so please point to the right code that does it.

Thanks,
Nimalan

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Yes of course you can remove only footers from the document. Please see the following code example:

Document doc = new Document("C:\\Temp\\in.doc");

for (int i = 0; i < doc.getSections().getCount(); i++)

{

//Loop through all headers/footers

for(HeaderFooter hf : doc.getSections().get(i).getHeadersFooters())

{

if(hf.getHeaderFooterType() == HeaderFooterType.FOOTER_EVEN ||

hf.getHeaderFooterType() == HeaderFooterType.FOOTER_FIRST ||

hf.getHeaderFooterType() == HeaderFooterType.FOOTER_PRIMARY)

{

hf.remove();

}

}

}

//save document

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards.

Thank you. That works.

Nimalan