Headers and Footers
RadRichTextEditor supports Headers and Footers in its document when in Paged layout mode.
Note that Headers and Footers are not persisted when exporting with HtmlFormatProvider. You can read more about this here
The topic contains the following sections:
Header Footer Types
The Headers and Footers are properties of a Section and each section in the document can have the following types of Headers and Footers:
Default - used all through the section;
First - used on the first page of the section only;
Even - to be used on every even page.
Customizing Headers And Footers
Here is an example how you can create a Header:
Header header = new Header() { Body = radDocument, IsLinkedToPrevious = false }; //radDocument is an instance of RadDocument, representing the content of a Header,
//typically contains a few paragraphs
Dim header As New Header() With {.Body = radDocument, .IsLinkedToPrevious = False} 'radDocument is an instance of RadDocument, representing the content of a Header,
'typically contains a few paragraphs
When it comes to using a Header created in this manner, this depends on the state of the document - if it has been measured or not.
- In a non-measured document, which you are building in code-behind, you can set the Default page Header of a section in the following way:
section.Headers.Default = header;
section.Headers.Default = header
- In a measured document (a document that has been previewed in the editor), you can change the Default page header of the first section like this:
this.radRichTextEditor1.UpdateHeader(this.radRichTextEditor1.Document.Sections.First, HeaderFooterType.Default, header);
Me.radRichTextEditor1.UpdateHeader(Me.radRichTextEditor1.Document.Sections.First, HeaderFooterType.Default, header)
All header/footer types - Default, First and Even are set identically. The only thing you should add when you set the First or Even Header/Footer of the document, is to set the property of the section that notifies the document to use different Header/Footer than the default one using one of the following properties:
this.radRichTextEditor1.Document.Sections.First.HasDifferentFirstPageHeaderFooter = true;
//or
this.radRichTextEditor1.Document.HasDifferentEvenAndOddHeadersFooters = true;
Me.radRichTextEditor1.Document.Sections.First.HasDifferentFirstPageHeaderFooter = True
'or
Me.radRichTextEditor1.Document.HasDifferentEvenAndOddHeadersFooters = True
Setting the Footers can be done in the same way. Here is the respective code for footers:
- Creating a Footer:
Footer footer = new Footer() { Body = radDocument, IsLinkedToPrevious = false }; //radDocument is an instance of RadDocument, representing the content of the footer
Dim footer As New Footer() With {.Body = radDocument, .IsLinkedToPrevious = False} 'radDocument is an instance of RadDocument, representing the content of the footer
Setting the Footer to be used in a particular section:
In a non-measured document:
section.Footers.Default = footer;
section.Footers.Default = footer
- In a measured document:
this.radRichTextEditor1.UpdateFooter(this.radRichTextEditor1.Document.Sections.First, HeaderFooterType.Default, footer);
Me.radRichTextEditor1.UpdateFooter(Me.radRichTextEditor1.Document.Sections.First, HeaderFooterType.Default, footer)
As for setting different footers for the first page or the even page, this is done by passing the respective parameter to the UpdateFooter method - HeaderFooterType. First or HeaderFooterType.Even and setting the corresponding property of the document/editor:
this.radRichTextEditor1.Document.Sections.First.HasDifferentFirstPageHeaderFooter = true;
//or
this.radRichTextEditor1.Document.HasDifferentEvenAndOddHeadersFooters = true;
Me.radRichTextEditor1.Document.Sections.First.HasDifferentFirstPageHeaderFooter = True
'or
Me.radRichTextEditor1.Document.HasDifferentEvenAndOddHeadersFooters = True
Disabling Headers and Footers
Headers and Footers are only present in Paged layout mode, so the easiest way to remove them is to change the layout mode. In case you wish to show documents in paged mode and still disable headers and footers, you can do so by removing the UI layer responsible for their visualization - HeaderFooterLayer.
The concept of UI layers and their usage are explained in this article.
class CustomUILayerBuilder : UILayersBuilder
{
protected override void BuildUILayersOverride(IUILayerContainer uiLayerContainer)
{
base.BuildUILayersOverride(uiLayerContainer);
uiLayerContainer.UILayers.Remove(DefaultUILayers.HeaderFooterLayer);
}
}
Friend Class CustomUILayerBuilder
Inherits UILayersBuilder
Protected Overrides Sub BuildUILayersOverride(ByVal uiLayerContainer As IUILayerContainer)
Me.BuildUILayersOverride(uiLayerContainer)
uiLayerContainer.UILayers.Remove(DefaultUILayers.HeaderFooterLayer)
End Sub
End Class