Class WHeadersFooters
Represents page headers and footers
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class WHeadersFooters : XDLSSerializableBase, IXDLSSerializable, IEnumerable
Examples
The following code example demonstrates how to add text to different types of headers and footers.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Creates a new document.
WordDocument document = new WordDocument();
//Adds the first section to the document.
IWSection section = document.AddSection();
//Adds a paragraph to the section.
IWParagraph paragraph = section.AddParagraph();
//Sets DifferentFirstPage and DifferentOddEvenPages to true for inserting Header and Footer text.
section.PageSetup.DifferentFirstPage = true;
section.PageSetup.DifferentOddAndEvenPages = true;
//Appends some text to the first page in document.
paragraph.AppendText("\r\r[ First Page ] \r\rText Body_Text Body_Text Body_Text Body_Text Body_Text Body");
paragraph.ParagraphFormat.PageBreakAfter = true;
//Appends some text to the second page in document.
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ Second Page ] \r\rText Body_Text Body_Text Body_Text Body_Text Body_Text Body");
paragraph.ParagraphFormat.PageBreakAfter = true;
//Appends some text to the third page in document.
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ Third Page ] \r\rText Body_Text Body_Text Body_Text Body_Text Body_Text Body");
//Inserts First Page Header.
paragraph = new WParagraph(document);
paragraph.AppendText("[ FIRST PAGE Header ]");
section.HeadersFooters.FirstPageHeader.Paragraphs.Add(paragraph);
//Inserts First Page Footer.
paragraph = new WParagraph(document);
paragraph.AppendText("[ FIRST PAGE Footer ]");
section.HeadersFooters.FirstPageFooter.Paragraphs.Add(paragraph);
//Inserts Odd Pages Header.
paragraph = new WParagraph(document);
paragraph.AppendText("[ ODD Page Header Text goes here ]");
section.HeadersFooters.OddHeader.Paragraphs.Add(paragraph);
//Inserts Odd Pages Footer.
paragraph = new WParagraph(document);
paragraph.AppendText("[ ODD Page Footer Text goes here ]");
section.HeadersFooters.OddFooter.Paragraphs.Add(paragraph);
//Inserts Even Pages Header.
paragraph = new WParagraph(document);
paragraph.AppendText("[ EVEN Page Header Text goes here ]");
section.HeadersFooters.EvenHeader.Paragraphs.Add(paragraph);
//Inserts Even Pages Footer.
paragraph = new WParagraph(document);
paragraph.AppendText("[ EVEN Page Footer Text goes here ]");
section.HeadersFooters.EvenFooter.Paragraphs.Add(paragraph);
//Adds the second section to the document.
section = document.AddSection();
section.PageSetup.DifferentFirstPage = true;
//Appends some text to the Second Sections's first page in the document.
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ First Page for SECOND SECTION ]\r[ ON DIFFERENT FIRTS PAGE ]\r\rText Body_Text Body_Text Body_Text Body_Text Body_Text Body");
paragraph.ParagraphFormat.PageBreakAfter = true;
//Appends some text to the Second Sections's second page in the document.
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ Second Page for SECOND SECTION ]\rText Body_Text Body_Text Body_Text Body_Text Body_Text Body");
//Inserts Second Sections's First Header.
paragraph = new WParagraph(document);
paragraph.AppendText("[ SECOND SECTION FIRST PAGE Header ]");
section.HeadersFooters.FirstPageHeader.Paragraphs.Add(paragraph);
//Inserts Second Sections's First Footer.
paragraph = new WParagraph(document);
paragraph.AppendText("[ SECOND SECTION FIRST PAGE Footer ]");
section.HeadersFooters.FirstPageFooter.Paragraphs.Add(paragraph);
//Inserts Second Sections's Header.
paragraph = new WParagraph(document);
paragraph.AppendText("SECOND SECTION Header Text goes here");
section.HeadersFooters.OddHeader.Paragraphs.Add(paragraph);
//Inserts Second Sections's Footer.
paragraph = new WParagraph(document);
paragraph.AppendText("SECOND SECTION Footer Text goes here");
section.HeadersFooters.OddFooter.Paragraphs.Add(paragraph);
//Saves the document to disk.
document.Save("Sample.docx", FormatType.Docx);
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Creates a new document.
Dim document As WordDocument = New WordDocument()
'Adds the first section to the document.
Dim section As IWSection = document.AddSection()
'Adds a paragraph to the section.
Dim paragraph As IWParagraph = section.AddParagraph()
'Sets DifferentFirstPage and DifferentOddEvenPages as true for inserting Header and Footer text.
section.PageSetup.DifferentFirstPage = True
section.PageSetup.DifferentOddAndEvenPages = True
'Appends some text to the first page in document.
paragraph.AppendText(Constants.VB.NETCr + Constants.VB.NETCr and "[ First Page ] " and Constants.VB.NETCr + Constants.VB.NETCr and "Text Body_Text Body_Text Body_Text Body_Text Body_Text Body")
paragraph.ParagraphFormat.PageBreakAfter = True
'Appends some text to the second page in document.
paragraph = section.AddParagraph()
paragraph.AppendText(Constants.VB.NETCr + Constants.VB.NETCr and "[ Second Page ] " and Constants.VB.NETCr + Constants.VB.NETCr and "Text Body_Text Body_Text Body_Text Body_Text Body_Text Body")
paragraph.ParagraphFormat.PageBreakAfter = True
'Appends some text to the third page in document.
paragraph = section.AddParagraph()
paragraph.AppendText(Constants.VB.NETCr + Constants.VB.NETCr and "[ Third Page ] " and Constants.VB.NETCr + Constants.VB.NETCr and "Text Body_Text Body_Text Body_Text Body_Text Body_Text Body")
'Inserts First Page Header.
paragraph = New WParagraph(document)
paragraph.AppendText("[ FIRST PAGE Header ]")
section.HeadersFooters.FirstPageHeader.Paragraphs.Add(paragraph)
'Inserts First Page Footer.
paragraph = New WParagraph(document)
paragraph.AppendText("[ FIRST PAGE Footer ]")
section.HeadersFooters.FirstPageFooter.Paragraphs.Add(paragraph)
'Inserts Odd Pages Header.
paragraph = New WParagraph(document)
paragraph.AppendText("[ ODD Page Header Text goes here ]")
section.HeadersFooters.OddHeader.Paragraphs.Add(paragraph)
'Inserts Odd Pages Footer.
paragraph = New WParagraph(document)
paragraph.AppendText("[ ODD Page Footer Text goes here ]")
section.HeadersFooters.OddFooter.Paragraphs.Add(paragraph)
'Inserts Even Pages Header.
paragraph = New WParagraph(document)
paragraph.AppendText("[ EVEN Page Header Text goes here ]")
section.HeadersFooters.EvenHeader.Paragraphs.Add(paragraph)
'Inserts Even Pages Footer.
paragraph = New WParagraph(document)
paragraph.AppendText("[ EVEN Page Footer Text goes here ]")
section.HeadersFooters.EvenFooter.Paragraphs.Add(paragraph)
'Adds the second section to the document.
section = document.AddSection()
section.PageSetup.DifferentFirstPage = True
'Appends some text to the Second Sections's first page in the document.
paragraph = section.AddParagraph()
paragraph.AppendText(Constants.VB.NETCr + Constants.VB.NETCr and "[ First Page for SECOND SECTION ]" and Constants.VB.NETCr and "[ ON DIFFERENT FIRTS PAGE ]" and Constants.VB.NETCr + Constants.VB.NETCr and "Text Body_Text Body_Text Body_Text Body_Text Body_Text Body")
paragraph.ParagraphFormat.PageBreakAfter = True
'Appends some text to the Second Sections's second page in the document.
paragraph = section.AddParagraph()
paragraph.AppendText(Constants.VB.NETCr + Constants.VB.NETCr and "[ Second Page for SECOND SECTION ]" and Constants.VB.NETCr and "Text Body_Text Body_Text Body_Text Body_Text Body_Text Body")
'Inserts Second Sections's First Header.
paragraph = New WParagraph(document)
paragraph.AppendText("[ SECOND SECTION FIRST PAGE Header ]")
section.HeadersFooters.FirstPageHeader.Paragraphs.Add(paragraph)
'Inserts Second Sections's First Footer.
paragraph = New WParagraph(document)
paragraph.AppendText("[ SECOND SECTION FIRST PAGE Footer ]")
section.HeadersFooters.FirstPageFooter.Paragraphs.Add(paragraph)
'Inserts Second Sections's Header.
paragraph = New WParagraph(document)
paragraph.AppendText("SECOND SECTION Header Text goes here")
section.HeadersFooters.OddHeader.Paragraphs.Add(paragraph)
'Inserts Second Sections's Footer.
paragraph = New WParagraph(document)
paragraph.AppendText("SECOND SECTION Footer Text goes here")
section.HeadersFooters.OddFooter.Paragraphs.Add(paragraph)
'Saves the document to disk.
document.Save("Sample.docx", FormatType.Docx)
End Sub
Properties
EvenFooter
Gets even pages footer of the document. Read-only.
Declaration
public HeaderFooter EvenFooter { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the even pages footer for the document. |
EvenHeader
Gets even pages header of the document. Read-only.
Declaration
public HeaderFooter EvenHeader { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the even pages header for the document. |
FirstPageFooter
Gets first page footer of the document. Read-only.
Declaration
public HeaderFooter FirstPageFooter { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the first page footer for the document. |
FirstPageHeader
Gets first page header of the document. Read-only.
Declaration
public HeaderFooter FirstPageHeader { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the first page header for the document. |
Footer
Gets default footer of the document. Read-only.
Declaration
public HeaderFooter Footer { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | the HeaderFooter instance that represents the default footer for the document. |
Header
Gets default header of the document. Read-only.
Declaration
public HeaderFooter Header { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the default header for the document. |
IsEmpty
Gets a value indicating whether all the headers/footers are empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the document has empty headers/footers; otherwise, false. |
Item[HeaderFooterType]
Gets TextBody of the header/footer of the document by specified HeaderFooter type.
Declaration
public HeaderFooter this[HeaderFooterType hfType] { get; }
Parameters
Type | Name | Description |
---|---|---|
HeaderFooterType | hfType |
Property Value
Type | Description |
---|---|
HeaderFooter |
Item[Int32]
Gets TextBody of the header/footer of the document at specified index.
Declaration
public HeaderFooter this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type | Description |
---|---|
HeaderFooter | The integer that represents the HeaderFooterType |
Remarks
The HeaderFooterType has 6 values which is used as index for this property.
Index 0 - EvenHeader
Index 1 - OddHeader
Index 2 - EvenFooter
Index 3 - OddFooter
Index 4 - FirstPageHeader
Index 5 - FirstPageFooter
LinkToPrevious
Gets or sets a value indicating whether the current header or footer is linked to the header or footer in the previous section.
Declaration
public bool LinkToPrevious { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the current header or footer is linked to the header or footer in the previous section, otherwise false. |
Remarks
This property always returns false for the first section, since there is no previous section for the first section.
Examples
The following code example demonstrates how to link the previous section header and footer for the current section.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new document
WordDocument document = new WordDocument();
//Add the first section to the document
IWSection section = document.AddSection();
//Insert the first section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ First Section Header ]");
//Insert the first section footer
section.HeadersFooters.Footer.AddParagraph().AppendText("[ First Section Footer ]");
//Add a paragraph to the section
IWParagraph paragraph = section.AddParagraph();
string paraText = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula";
//Append some text to the first page in document
paragraph.AppendText("\r\r[ First Page ] \r\r" + paraText);
//Add the second section to the document
section = document.AddSection();
//Insert the second section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ Second Section Header ]");
//Insert the second section footer.
section.HeadersFooters.Footer.AddParagraph().AppendText("[ Second Section Footer ]");
//Set LinkToPrevious as true for retrieve the header and footer from previous section
section.HeadersFooters.LinkToPrevious = true;
//Append some text to the second page in document
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ Second Page ] \r\r" + paraText);
//Add the third section to the document
section = document.AddSection();
//Insert the third section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ Third Section Header ]");
//Insert the third section footer
section.HeadersFooters.Footer.AddParagraph().AppendText("[ Third Section Footer ]");
//Append some text to the third page in document
paragraph = section.AddParagraph();
paragraph.AppendText("\r\r[ Third Page ] \r\r" + paraText);
//Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new document
Dim document As New WordDocument()
'Add the first section to the document
Dim section As IWSection = document.AddSection()
'Insert the first section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ First Section Header ]")
'Insert the first section footer
section.HeadersFooters.Footer.AddParagraph().AppendText("[ First Section Footer ]")
'Add a paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
Dim paraText As String = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula"
'Append some text to the first page in document
paragraph.AppendText(Convert.ToString(vbCr & vbCr & "[ First Page ] " & vbCr & vbCr) & paraText)
'Add the second section to the document
section = document.AddSection()
'Insert the second section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ Second Section Header ]")
'Insert the second section footer
section.HeadersFooters.Footer.AddParagraph().AppendText("[ Second Section Footer ]")
'Set LinkToPrevious as true for retrieve the header and footer from previous section
section.HeadersFooters.LinkToPrevious = True
'Append some text to the second page in document
paragraph = section.AddParagraph()
paragraph.AppendText(Convert.ToString(vbCr & vbCr & "[ Second Page ] " & vbCr & vbCr) & paraText)
'Add the third section to the document
section = document.AddSection()
'Insert the third section header
section.HeadersFooters.Header.AddParagraph().AppendText("[ Third Section Header ]")
'Insert the third section footer
section.HeadersFooters.Footer.AddParagraph().AppendText("[ Third Section Footer ]")
'Append some text to the third page in document
paragraph = section.AddParagraph()
paragraph.AppendText(Convert.ToString(vbCr & vbCr & "[ Third Page ] " & vbCr & vbCr) & paraText)
�Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
OddFooter
Gets odd pages footer of the document. Read-only.
Declaration
public HeaderFooter OddFooter { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the odd pages footer for the document. |
Remarks
This is also the default footer for the document.
OddHeader
Gets odd pages header of the document. Read-only.
Declaration
public HeaderFooter OddHeader { get; }
Property Value
Type | Description |
---|---|
HeaderFooter | The HeaderFooter instance that represents the odd pages header for the document. |
Remarks
This is also the default header for the document
Methods
CloneImpl()
Clones itself.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | Returns cloned object. |
Overrides
GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
public IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An System.Collections.IEnumerator object that can be used to iterate through the collection. |
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()