Click or drag to resize
HeaderFooterCollection Class
Represents a collection of HeaderFooter elements.
Inheritance Hierarchy
SystemObject
  GemBox.DocumentElementCollection
    GemBox.DocumentElementCollectionHeaderFooter
      GemBox.DocumentHeaderFooterCollection

Namespace:  GemBox.Document
Assembly:  GemBox.Document (in GemBox.Document.dll) Version: 25.3.30.1255
Syntax
public sealed class HeaderFooterCollection : ElementCollection<HeaderFooter>

The HeaderFooterCollection type exposes the following members.

Properties
Methods
  NameDescription
Public methodAdd (Inherited from ElementCollectionT.)
Public methodCastTElement
Gets the element at the specified index and casts it to the specified type.
(Inherited from ElementCollectionT.)
Public methodClear (Inherited from ElementCollectionT.)
Public methodContains (Inherited from ElementCollectionT.)
Public methodCopyTo(T, Int32) (Inherited from ElementCollectionT.)
Public methodCopyTo(Element, Int32)
Copies the elements of the ElementCollection to an Array, starting at a particular Array index.
(Inherited from ElementCollection.)
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
(Inherited from ElementCollectionT.)
Public methodIndexOf (Inherited from ElementCollectionT.)
Public methodInsert (Inherited from ElementCollectionT.)
Public methodRemove (Inherited from ElementCollectionT.)
Public methodRemoveAt (Inherited from ElementCollectionT.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodIListAdd
Adds an item to the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListContains
Determines whether the IList contains a specific value.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodICollectionCopyTo
Copies the elements of the ICollection to an Array, starting at a particular Array index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIEnumerableGetEnumerator
Returns an enumerator that iterates through a collection.
(Inherited from ElementCollectionT.)
Explicit interface implementationPrivate methodIListIndexOf
Determines the index of a specific item in the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListInsert
Inserts an item to the IList at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListIsFixedSize
Gets a value indicating whether the IList has a fixed size.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListIsReadOnly
Gets a value indicating whether the IList is read-only.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyICollectionTIsReadOnly (Inherited from ElementCollectionT.)
Explicit interface implementationPrivate propertyICollectionIsSynchronized
Gets a value indicating whether access to the ICollection is synchronized (thread safe).
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListItem
Gets or sets the element at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListRemove
Removes the first occurrence of a specific object from the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyICollectionSyncRoot
Gets an object that can be used to synchronize access to the ICollection.
(Inherited from ElementCollection.)
Top
Remarks

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