Free Support Forum - aspose.com

Remove header footer in docx file


#1

remove header and footer in docx file. Then write this code.
Because I don’t want header footer data and also page number.
Document doc = new Document(MyDir + “in.docx”);
doc.Save(MyDir + “output.txt”);
@tahir.manzoor


#2

@rabin.samanta,

The following code should help:

Document doc = new Document("E:\\temp\\input.docx");

foreach (Section sec in doc.Sections)
{
    sec.ClearHeadersFooters();
}

doc.Save("E:\\temp\\19.2.docx");

#3

@awais.hafeez
thanks
But i also want to remove the page number . how to remove it.


#4

this code i am not able to build in maven.what is the dependency for it


#5

@rabin.samanta,

Please ZIP and attach your sample Word document here for testing. We will then investigate the issue on our end and provide you more information.

You need to add Aspose.Words for .NET DLL reference in your project to be able to run this code.
https://downloads.aspose.com/words/net


#6

test.zip (12.2 KB)
I am upload .docx and converted .txt file.
i need only body data not header and footer data in .txt file


#7

@rabin.samanta,

The following code should help:

Document doc = new Document("E:\\test\\test.docx");

TxtSaveOptions opts = new TxtSaveOptions();
opts.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE);

doc.save("E:\\test\\awjava-19.1.txt", opts);