Headers and Footers in Blazor DocumentEditor Component

17 Oct 20251 minute to read

Headers and footers are the areas in the top and bottom margins of each page in a document. They are typically used to display content that repeats across multiple pages, such as document titles, company logos, page numbers, and dates.

The Blazor Document Editor supports headers and footers in its document. Each section in the document can have the following types of headers and footers:

  • First Page: A unique header and footer that appears only on the first page of the section.
  • Even Pages: A header and footer that appears on all even-numbered pages in the section.
  • Default: A header and footer that appears on all pages of the section, where first or even pages are not applicable or not specified.

This can be defined by setting the format properties of the corresponding section.

//Defines whether different header footer is required for first page of the section
await container.DocumentEditor.Selection.SectionFormat.SetDifferentFirstPageAsync(true);
//Defines whether different header footer is required for odd and even pages in the section
await container.DocumentEditor.Selection.SectionFormat.SetDifferentOddAndEvenPagesAsync(true);

Double click in header or footer region to move the selection into it. This can also be done using the following code.

await container.DocumentEditor.Selection.GoToHeaderAsync();

await container.DocumentEditor.Selection.GoToFooterAsync();

The distance of the header region content from the top of the page can be defined. Refer to the following sample code.

await container.DocumentEditor.Selection.SectionFormat.SetHeaderDistanceAsync(36);

Same way, you can define the distance of footer region content from the bottom of the page. Refer to the following sample code.

await container.DocumentEditor.Selection.SectionFormat.SetFooterDistanceAsync(36);

Move the selection to the document body from header or footer region by double clicking or tapping the document area. You can also perform this by using the following sample code.

await container.DocumentEditor.Selection.CloseHeaderFooterAsync();

You can also explore our Blazor Word Processor example to know how to render and configure the document editor.