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

Free Support Forum - aspose.com

Header and Footer clear method

Hi

I want to delete the header or footer depending on our requirment.

At present I see that there is only

section.HeadersFooters.Clear(); Which will delete both header and footer in the section.

Is there some method which will delete only Header or footer.

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

Thanks for your request. I think that the following code could be useful for you.

Document doc = new Document(@"Test161\in.doc");

//Loop through all section in document

foreach (Section section in doc.Sections)

{

//Loop through HeaderFooter nodes

foreach (HeaderFooter hf in section.HeadersFooters)

{

//Remove Primary footer (as an example)

if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

hf.Remove();

}

}

//Save output document

doc.Save(@"Test161\out.doc");

Hope this helps.

Best regards.

Hi

This will work only if section.HeadersFooters count is 1 .

but if I have count more than one it will not loop through all.

foreach (Section section in doc.Sections)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

//Loop through HeaderFooter nodes

foreach (HeaderFooter hf in section.HeadersFooters)

{

//Remove Primary footer (as an example)

if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

hf.Remove();

}

}

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

Thanks for your request. Please try using the following code:

Document doc = new Document(@"Test161\in.doc");

//Loop through all section in document

foreach (Section section in doc.Sections)

{

ArrayList hfList = new ArrayList();

//Loop through HeaderFooter nodes

foreach (HeaderFooter hf in section.HeadersFooters)

{

//Remove Primary footer (as an example)

if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

hfList.Add(hf);

}

//Remove headerfooters

foreach (HeaderFooter hf in hfList)

{

hf.Remove();

}

}

//Save output document

doc.Save(@"Test161\out.doc");

Hope this helps.

Best regards.

Thanks,This helps

Hi,

I want to remove just one specific page header alone. Like, i want to remove just 29th page header alone in a whole 50 pages Word document. Could you please let me know whether its possible, could you please advice?

Thanks,
Albert

Hello Albert,

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

Thanks for your request. I’m afraid there is no way to achieve what you need using Aspose.Words. Also even using MS Word it’s impossible.

It sounds real, just in case of using sections. I mean if each page inside your document will be separate section, you will be able to remove header/footer for current section.

Please see the following link to learn more about headers/footers in MS Word:

http://office.microsoft.com/en-us/word-help/insert-headers-and-footers-HP001226486.aspx

Best regards,

Hi Andrey,

Thanks for your quick response. Could you please let me know whether its possible using Aspose PDF?

Thanks,
Albert Samuel
Universal American

I mean, initially we have the memory stream being saved as document and then we process the document and finally we save it as PDF. So, i just though of checking whether i can make use of Aspose.PDF or Kit to remove the header for one specific page alone?

Thanks,
Albert

Hi

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

Thanks for your inquiry. Regarding Aspose.Pdf and Aspose.Pdf.Kit you can ask your question in the appropriate forums:

http://www.aspose.com/community/forums/aspose.pdf-product-family/20/showforum.aspx

http://www.aspose.com/community/forums/aspose.pdf.kit-product-family/215/showforum.aspx

My colleagues will answer you shortly.

Best regards,

Thank You!

Thanks,
Albert