Click or drag to resize

HeaderFooterCollection Class

Represents a collection of HeaderFooter elements.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElementCollection
    SautinSoft.DocumentElementCollectionHeaderFooter
      SautinSoft.DocumentHeaderFooterCollection

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

The HeaderFooterCollection type exposes the following members.

Properties
  NameDescription
Public propertyContent
Gets the ContentRange of this collection.
(Inherited from ElementCollection.)
Public propertyCount
Gets the number of elements contained in this collection.
(Inherited from ElementCollection.)
Public propertyItemInt32
Gets or sets the element at the specified index.
(Inherited from ElementCollectionT.)
Public propertyItemHeaderFooterType
Gets the HeaderFooter with the specified type. Returns if collection doesn't contain HeaderFooter with the specified type.
Public propertySupportedElementTypes
Gets a sequence of ElementTypes that can be contained in this collection.
(Inherited from ElementCollection.)
Top
Methods
  NameDescription
Public methodAdd (Inherited from ElementCollectionT.)
Public methodClear
Removes all elements from this collection.
(Inherited from ElementCollection.)
Public methodContains (Inherited from ElementCollectionT.)
Public methodCopyTo(T, Int32) (Inherited from ElementCollectionT.)
Public methodCopyTo(Element, Int32)
Copies the entire collection to an Array, starting at a particular Array index.
(Inherited from ElementCollection.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Gets an enumerator that iterates through the collection.
(Inherited from ElementCollectionT.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf (Inherited from ElementCollectionT.)
Public methodInsert (Inherited from ElementCollectionT.)
Public methodRemove (Inherited from ElementCollectionT.)
Public methodCode exampleRemoveAt
Removes the element at the specified index.
(Inherited from ElementCollection.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
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 ElementCollection.)
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 methodIListRemoveAt
Removes the IList item at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyICollectionSyncRoot
Gets an object that can be used to synchronize access to the ICollection.
(Inherited from ElementCollection.)
Top
Examples
How to add a header and footer in the document using C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            HeadersAndFooters();
        }

        /// <summary>
        /// How to add a header and footer into a document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/headersfooters.php
        /// </remarks>
        public static void HeadersAndFooters()
        {
            string documentPath = @"HeadersAndFooters.docx";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add a new section in the document.
            Section s = new Section(dc);
            dc.Sections.Add(s);

            // Let's add a paragraph with text.
            Paragraph p = new Paragraph(dc);
            dc.Sections[0].Blocks.Add(p);

            p.ParagraphFormat.Alignment = HorizontalAlignment.Justify;
            p.Content.Start.Insert("Once upon a time, in a far away swamp, there lived an ogre named Shrek whose precious " +
                                   "solitude is suddenly shattered by an invasion of annoying fairy tale characters...", new CharacterFormat() { Size = 12, FontName = "Arial" });

            // Create a new header with formatted text.
            HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
            header.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona.", new CharacterFormat() { Size = 14.0 });

            // Add the header into HeadersFooters collection of the 1st section.
            s.HeadersFooters.Add(header);

            // Create a new footer with some text and image.
            HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);

            // Create a paragraph to insert it into the footer.
            Paragraph par = new Paragraph(dc);
            par.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona. ", new CharacterFormat() { Size = 14.0 });
            par.ParagraphFormat.Alignment = HorizontalAlignment.Left;

            // Insert image into the paragraph.
            double wPt = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point);
            double hPt = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point);

            Picture pict = new Picture(dc, Layout.Inline(new Size(wPt, hPt)), @"..\..\image1.jpg");
            par.Inlines.Add(pict);

            // Add the paragraph into the Blocks collection of the footer.
            footer.Blocks.Add(par);

            // Finally, add the footer into 1st section (HeadersFooters collection).
            s.HeadersFooters.Add(footer);

            // Save the document into DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to add a header and footer in the document using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing

Module Sample
    Sub Main()
        HeadersAndFooters()
    End Sub

    ''' <summary>
    ''' How to add a header and footer into a document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/headersfooters.php
    ''' </remarks>
    Sub HeadersAndFooters()
        Dim documentPath As String = "HeadersAndFooters.docx"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add a new section in the document.
        Dim s As New Section(dc)
        dc.Sections.Add(s)

        ' Let's add a paragraph with text.
        Dim p As New Paragraph(dc)
        dc.Sections(0).Blocks.Add(p)

        p.ParagraphFormat.Alignment = HorizontalAlignment.Justify
        p.Content.Start.Insert("Once upon a time, in a far away swamp, there lived an ogre named Shrek whose precious " & "solitude is suddenly shattered by an invasion of annoying fairy tale characters...", New CharacterFormat() With {
            .Size = 12,
            .FontName = "Arial"
        })

        ' Create a new header with formatted text.
        Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
        header.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona.", New CharacterFormat() With {.Size = 14.0})

        ' Add the header into HeadersFooters collection of the 1st section.
        s.HeadersFooters.Add(header)

        ' Create a new footer with some text and image.
        Dim footer As New HeaderFooter(dc, HeaderFooterType.FooterDefault)

        ' Create a paragraph to insert it into the footer.
        Dim par As New Paragraph(dc)
        par.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona. ", New CharacterFormat() With {.Size = 14.0})
        par.ParagraphFormat.Alignment = HorizontalAlignment.Left

        ' Insert image into the paragraph.
        Dim wPt As Double = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point)
        Dim hPt As Double = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point)

        Dim pict As New Picture(dc, Layout.Inline(New Size(wPt, hPt)), "..\image1.jpg")
        par.Inlines.Add(pict)

        ' Add the paragraph into the Blocks collection of the footer.
        footer.Blocks.Add(par)

        ' Finally, add the footer into 1st section (HeadersFooters collection).
        s.HeadersFooters.Add(footer)

        ' Save the document into DOCX format.
        dc.Save(documentPath)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also