Click or drag to resize
HeaderFooterType Enumeration
Specifies the type of the HeaderFooter.

Namespace: GemBox.Document
Assembly: GemBox.Document (in GemBox.Document.dll) Version: 25.3.30.1213
Syntax
public enum HeaderFooterType
Members
  Member nameValueDescription
HeaderDefault0 Default header.
HeaderEven1 Header for even pages.
HeaderFirst2 Header for the first page in section.
FooterDefault3 Default footer.
FooterEven4 Footer for even pages.
FooterFirst5 Footer for the first page in section.
Remarks

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

  • HeaderDefault / FooterDefault - header / footer will be applied to every page in a section.
  • HeaderEven / FooterEven - header / footer will be applied to only even pages in a section. Overrides HeaderDefault / FooterDefault on even pages, if also contained in a collection.
  • HeaderFirst / FooterFirst - header / footer will be applied to only first page in a section. Overrides both HeaderDefault / FooterDefault and HeaderEven / FooterEven on first page, if also 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