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

# How to remove all the content from a document but should retain the page boarder, header and footer

Hi,

I am using a upload document and then will change some special words with values using IReplace interface. For certain case I have to remove all the content after replacing it, but should show the exact empty pages(page number should be same after removing the content). Also after emptying the page page boarder, header and footer shouldn’t remove. So can you please help me to figure out a solution for this problem.

Thank you

@Gptrnt MS Word document consist of Sections. Each section has Headers/Footers and the main body. So if the document contains only one section and it is required to remove everything except Header/Footer, you should simply remove all content from the section’s body. For example see the following code:

Document doc = new Document("C:\\Temp\\in.docx");
doc.getFirstSection().getBody().removeAllChildren();
doc.save("C:\\Temp\\out.docx");


Please see our documentation to learn more about Aspose.Words Document Object model:
https://docs.aspose.com/words/java/aspose-words-document-object-model/

Hi,

Sometimes my document contains more than one section in the content, So in that case I need to find the section which has header and footer. Is there any property to find it ?

Thank you

@Gptrnt You can check the headers/footers count in the section to determine whether it has headers/footers or not:

boolean hasHeadersFooter = doc.getFirstSection().getHeadersFooters().getCount()>0;