ClearHeadersFooters
Contents
[
Hide
]ClearHeadersFooters()
Clears the headers and footers of this section.
public void ClearHeadersFooters()
Remarks
The text of all headers and footers is cleared, but HeaderFooter
objects themselves are not removed.
This makes headers and footers of this section linked to headers and footers of the previous section.
Examples
Shows how to clear the contents of all headers and footers in a section.
Document doc = new Document();
Assert.AreEqual(0, doc.FirstSection.HeadersFooters.Count);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Writeln("This is the primary header.");
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Writeln("This is the primary footer.");
Assert.AreEqual(2, doc.FirstSection.HeadersFooters.Count);
Assert.AreEqual("This is the primary header.", doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim());
Assert.AreEqual("This is the primary footer.", doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetText().Trim());
// Empty all the headers and footers in this section of all their contents.
// The headers and footers themselves will still be present but will have nothing to display.
doc.FirstSection.ClearHeadersFooters();
Assert.AreEqual(2, doc.FirstSection.HeadersFooters.Count);
Assert.AreEqual(string.Empty, doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim());
Assert.AreEqual(string.Empty, doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetText().Trim());
See Also
- class Section
- namespace Aspose.Words
- assembly Aspose.Words
ClearHeadersFooters(bool)
Clears the headers and footers of this section.
public void ClearHeadersFooters(bool preserveWatermarks)
Parameter | Type | Description |
---|---|---|
preserveWatermarks | Boolean | True if the watermarks shall not be removed. |
Remarks
The text of all headers and footers is cleared, but HeaderFooter
objects themselves are not removed.
This makes headers and footers of this section linked to headers and footers of the previous section.
Examples
Shows how to clear the contents of header and footer with or without a watermark.
Document doc = new Document(MyDir + "Header and footer types.docx");
// Add a plain text watermark.
doc.Watermark.SetText("Aspose Watermark");
// Make sure the headers and footers have content.
HeaderFooterCollection headersFooters = doc.FirstSection.HeadersFooters;
Assert.AreEqual("First header", headersFooters[HeaderFooterType.HeaderFirst].GetText().Trim());
Assert.AreEqual("Second header", headersFooters[HeaderFooterType.HeaderEven].GetText().Trim());
Assert.AreEqual("Third header", headersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim());
Assert.AreEqual("First footer", headersFooters[HeaderFooterType.FooterFirst].GetText().Trim());
Assert.AreEqual("Second footer", headersFooters[HeaderFooterType.FooterEven].GetText().Trim());
Assert.AreEqual("Third footer", headersFooters[HeaderFooterType.FooterPrimary].GetText().Trim());
// Removes all header and footer content except watermarks.
doc.FirstSection.ClearHeadersFooters(true);
headersFooters = doc.FirstSection.HeadersFooters;
Assert.AreEqual("", headersFooters[HeaderFooterType.HeaderFirst].GetText().Trim());
Assert.AreEqual("", headersFooters[HeaderFooterType.HeaderEven].GetText().Trim());
Assert.AreEqual("", headersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim());
Assert.AreEqual("", headersFooters[HeaderFooterType.FooterFirst].GetText().Trim());
Assert.AreEqual("", headersFooters[HeaderFooterType.FooterEven].GetText().Trim());
Assert.AreEqual("", headersFooters[HeaderFooterType.FooterPrimary].GetText().Trim());
Assert.AreEqual(WatermarkType.Text, doc.Watermark.Type);
// Removes all header and footer content including watermarks.
doc.FirstSection.ClearHeadersFooters(false);
Assert.AreEqual(WatermarkType.None, doc.Watermark.Type);
See Also
- class Section
- namespace Aspose.Words
- assembly Aspose.Words