Click or drag to resize
SectionHeadersFooters Property
Gets the Section's headers / footers.

Namespace: GemBox.Document
Assembly: GemBox.Document (in GemBox.Document.dll) Version: 25.3.30.1231
Syntax
public HeaderFooterCollection HeadersFooters { get; }

Property Value

Type: HeaderFooterCollection
The Section's headers / footers.
Remarks

Since HeaderFooter class is , only supported element in this collection is HeaderFooter.

HeaderFooterCollection cannot contain multiple HeaderFooter elements with equal HeaderFooter.HeaderFooterType.

Following rules apply for HeaderFooterType headers / footers contained in a collection:

Examples

Following example shows different header / footer types and their precedence rules.

static void CreateHeaderFooterDocuments()
{
    // Create a document with default header / footer.
    CreateHeaderFooterDocument("DefaultHeaderFooter.docx", HeaderFooterType.HeaderDefault, HeaderFooterType.FooterDefault);

    // Create a document with even pages header / footer and default header / footer.
    CreateHeaderFooterDocument("EvenHeaderFooter.docx", HeaderFooterType.HeaderEven, HeaderFooterType.HeaderDefault, HeaderFooterType.FooterEven, HeaderFooterType.FooterDefault);

    // Create a document with first page header / footer, even pages header / footer and default header / footer.
    CreateHeaderFooterDocument("FirstHeaderFooter.docx", HeaderFooterType.HeaderFirst, HeaderFooterType.HeaderEven, HeaderFooterType.HeaderDefault, HeaderFooterType.FooterFirst, HeaderFooterType.FooterEven, HeaderFooterType.FooterDefault);
}

// Creates a document with specified header / footer types, saves a document to the Desktop and opens it Microsoft Word.
static void CreateHeaderFooterDocument(string documentName, params HeaderFooterType[] headerFooterTypes)
{
    // Create a new empty document.
    var doc = new DocumentModel();

    // Add content that is broken across pages to see different header / footer types in action.
    var section = new Section(doc, new Paragraph(doc,
        new Run(doc, "First page content"),
        new SpecialCharacter(doc, SpecialCharacterType.PageBreak),
        new Run(doc, "Second page content"),
        new SpecialCharacter(doc, SpecialCharacterType.PageBreak),
        new Run(doc, "Third page content"),
        new SpecialCharacter(doc, SpecialCharacterType.PageBreak),
        new Run(doc, "Fourth page content"),
        new SpecialCharacter(doc, SpecialCharacterType.PageBreak),
        new Run(doc, "Fifth page content")));

    // Add headers / footers.
    foreach (var headerFooterType in headerFooterTypes)
        section.HeadersFooters.Add(new HeaderFooter(doc, headerFooterType, new Paragraph(doc, headerFooterType.ToString())));

    doc.Sections.Add(section);

    // Document will be saved on the Desktop.
    var path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), documentName);

    // Save the document.
    doc.Save(path);

    // Open the document in Microsoft Word.
    System.Diagnostics.Process.Start(path);
}
See Also