# Headers and Footers

`Header` and `Footer` elements are block containers in the RadWordsProcessing document model, so they can contain paragraphs and tables. Each [Section](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/section) exposes three header slots and three footer slots that let you define different content for the first page, even pages, and the default page flow.

Use this article to understand the available header and footer types, how section settings affect them, and how to create, retrieve, and reuse them in a flow document.

## Available Types

Headers and footers are properties of a `Section`. Each section can define these header and footer types:

| Type      | Description                                                                                         |
| --------- | --------------------------------------------------------------------------------------------------- |
| `Default` | Used for the section pages unless a more specific first-page or even-page header or footer applies. |
| `First`   | Used only on the first page of the section.                                                         |
| `Even`    | Used on even-numbered pages of the section when even and odd headers or footers are enabled.        |

## Which Settings Control Header and Footer Output

The header or footer that appears on a page depends on both the content you assign and the section-level settings that enable specific variants:

* `RadFlowDocument.HasDifferentEvenOddPageHeadersFooters` controls whether the `Even` header and footer are used for even-numbered document pages.
* `Section.HasDifferentFirstPageHeaderFooter` controls whether the `First` header and footer are used on the first page of the section.
* `Section.HeaderTopMargin` sets the top margin for the header area in device-independent pixels, where `96` pixels equal `1` inch.
* `Section.FooterBottomMargin` sets the bottom margin for the footer area in device-independent pixels.

If the even and odd setting is `false`, the section ignores the `Even` header and footer. If the first-page setting is `false`, the section ignores the `First` header and footer.

## Inserting Header/Footer

Create headers and footers through the section properties for the required `HeaderFooterType`.

Use the following example to create a header:

### Example: Create default, first-page, and even-page headers for a section

```C#
RadFlowDocument document = new RadFlowDocument();
Section section = document.Sections.AddSection();

document.Sections.First().Headers.Add(); // Creates the default Header.
document.Sections.First().Headers.Add(HeaderFooterType.First);
document.Sections.First().Headers.Add(HeaderFooterType.Even);
```

Use the following example to create a footer:

### Example: Create default, first-page, and even-page footers for a section

```C#
RadFlowDocument document = new RadFlowDocument();
Section section = document.Sections.AddSection();

document.Sections.First().Footers.Add(); // Creates the default Footer.
document.Sections.First().Footers.Add(HeaderFooterType.First);
document.Sections.First().Footers.Add(HeaderFooterType.Even);
```

> note The `Parent` property of `Header` and `Footer` contains a reference to the `Section` from which the object is obtained.

## Operating with Headers and Footers

You can access the headers and footers of a section through the `Default`, `Even`, and `First` properties of the section `Headers` and `Footers` collections.

The following example gets the default header of a section:

### Example: Get the default header from a section

```C#
Header defaultHeader = section.Headers.Default;
```

The following example gets the default footer of a section:

### Example: Get the default footer from a section

```C#
Footer defaultFooter = section.Footers.Default;
```

> note If a header or footer of a given type is not added, the corresponding property value is `null`.

The following example adds different headers for odd and even pages:

### Example: Add different default and even-page headers to the document

```C#
RadFlowDocument document = new RadFlowDocument();
document.Sections.AddSection();
document.HasDifferentEvenOddPageHeadersFooters = true;

Header defaultHeader = document.Sections.First().Headers.Add();
Paragraph defaultHeaderParagraph = defaultHeader.Blocks.AddParagraph();
defaultHeaderParagraph.TextAlignment = Alignment.Right;
defaultHeaderParagraph.Inlines.AddRun("This is a sample odd page header.");

Header evenHeader = document.Sections.First().Headers.Add(HeaderFooterType.Even);
Paragraph evenHeaderParagraph = evenHeader.Blocks.AddParagraph();
evenHeaderParagraph.TextAlignment = Alignment.Left;
evenHeaderParagraph.Inlines.AddRun("This is a sample even page header.");
```

### Linking Headers/Footers to Previous Section Headers/Footers

When a section omits a header or footer of a given type, applications that visualize the flow document can inherit that header or footer from the previous section. This behavior is commonly described as linked to previous. If the document has no previous section, a blank header or footer is used instead.

For example, if a document has two sections and only the first section defines the `Default`, `Even`, and `First` headers or footers, the second section can render with the same content. If you want the second section to display blank headers or footers, assign explicit blank header or footer content for that section.

### Adding Watermarks to Header

`Header` elements expose a `Watermarks` collection. Use its `Add()` method to add a `Watermark` to a specific header instance.

For more information about supported watermark types and usage patterns, see [Watermark](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/watermark).

## Adding Fields to Header/Footer

You can add `PAGE`, `DATE`, and other fields to headers and footers so the content updates automatically as the document changes. For implementation details, see [Working with Fields](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/fields).

## See Also

* [HeaderFooterBase API Reference](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.HeaderFooterBase.html)
* [Document Model](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/model)
* [Section](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/section)
* [Working with Fields](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/fields)
* [Watermark](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/watermark)
* [Draw Header/Footer in RadFixedDocument](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/DrawHeaderFooter)
* [Create headers with left, center, and right text or images in exported PDF documents](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/customize-headers-pdf-radwordsprocessing)
