Skip to main content

Footnotes and Endnotes in Rich Text Documents

  • 10 minutes to read

The Rich Text Editor allows you to manage footnotes and endnotes. Footnotes appear at the bottom of the page and endnotes at the end of the document.

The RichEditControl supports footnotes/endnotes in printed documents and the following file formats:

  • DOCX
  • DOC
  • RTF
  • ODT
  • PDF (export only).

The Document.Footnotes and Document.Endnotes properties retrieve the collection of footnotes and endnotes. You can insert new notes and access, edit, and remove existing notes.

Insert a Note

In Code

Call the NoteCollection.Insert method to insert a note at a specific position. Pass the symbol used to mark a reference to insert a note with a custom mark. The code samples below show how to insert new footnotes and endnotes.

View Example

Footnote

footnotes-insert

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

private void InsertFootnotes(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Insert a footnote at the end of the 6th paragraph:
    DocumentPosition footnotePosition = 
    document.CreatePosition(document.Paragraphs[5].Range.End.ToInt() - 1);
    document.Footnotes.Insert(footnotePosition);

    //Insert a footnote at the last paragraph 
    //in the section with a custom mark:
    int l = document.Sections[0].Paragraphs.Count - 1;
    DocumentPosition footnoteWithCustomMarkPosition =
    document.CreatePosition(document.Paragraphs[l].Range.End.ToInt() - 1);
    document.Footnotes.Insert(footnoteWithCustomMarkPosition, "\u00BA");
}

Endnote

endnote-insert

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

private void InsertEndnotes(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Insert an endnote at the end of the last paragraph:
    DocumentPosition endnotePosition = 
    document.CreatePosition(document.Paragraphs[document.Paragraphs.Count - 1].Range.End.ToInt() - 1);
    document.Endnotes.Insert(endnotePosition);

    //Insert an endnote at the end of 
    //the second last paragraph with a custom mark:
    DocumentPosition endnoteWithCustomMarkPosition = 
    document.CreatePosition(document.Paragraphs[document.Paragraphs.Count - 2].Range.End.ToInt() - 2);
    document.Endnotes.Insert(endnoteWithCustomMarkPosition, "\u002a");
}

From the User Interface

Use buttons on the References Ribbon tab to insert a footnote or endnote.

notes ribbon ui

Access and Edit a Note

In Code

Access notes by their index in the NoteCollection. An indexer returns a Note object.

Use the Note.BeginUpdate() - Note.EndUpdate() paired methods to initiate the update session and access the note content (the SubDocument object).

The table below lists API you can use to edit the note content:

API Description
SubDocument.Range Retrieves the range of the note’s content.
SubDocument.CreateRange() Defines a document range. Use this method to modify a part of a note.
SubDocument.Delete() Removes all or part of the note’s content.
SubDocument.AppendText()
SubDocument.InsertText()
Adds the specified text.
SubDocument.BeginUpdateCharacters()
SubDocument.EndUpdateCharacters()
Initiates the update session and provides access to CharacterProperties for the specified range.

The code samples below show how to change the footnote and endnote text:

Footnote

Footnote

static void EditFootnote(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Access the first footnote's content:
    SubDocument footnote = document.Footnotes[0].BeginUpdate();

    //Exclude the reference mark and the space after it
    //from the range to be edited:
    DocumentRange footnoteTextRange = 
    footnote.CreateRange(footnote.Range.Start.ToInt() + 2, footnote.Range.Length
        - 2);

    //Clear the range:
    footnote.Delete(footnoteTextRange);

    //Append a new text:
    footnote.AppendText("the text is removed");

    //Finalize the update:
    document.Footnotes[0].EndUpdate(footnote);
}

Endnote

Endnote

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

static void EditEndnote(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Access the first endnote's content:
    SubDocument endnote = document.Endnotes[0].BeginUpdate();

    //Exclude the reference mark and the space after it 
    //from the range to be edited:
    DocumentRange endnoteTextRange = 
    endnote.CreateRange(endnote.Range.Start.ToInt() + 2, endnote.Range.Length
        - 2);

    //Access the range's character properties:
    CharacterProperties characterProperties = 
    endnote.BeginUpdateCharacters(endnoteTextRange);

    characterProperties.ForeColor = System.Drawing.Color.Red;
    characterProperties.Italic = true;

    //Finalize the character options update:
    endnote.EndUpdateCharacters(characterProperties);

    //Finalize the endnote update:
    document.Endnotes[0].EndUpdate(endnote);
}

From the User Interface

The Footnotes ribbon group on the References tab allows users to navigate to the next/previous note.

ribbon navigate

Click Show Notes to invoke the Show Notes dialog. Select the footnote or endnote area to show to the first footnote or endnote after the cursor’s position.

show-notes

You can edit a note’s content as regular text. Refer to the following help article for information on how to format text: Text Formatting.

Edit a Note Separator

Footnotes and endnotes can have the following separators:

  • Separator - separates footnotes or endnotes from the main text;
  • Continuation Separator - separates the main text from the notes that continue from the previous page;
  • Continuation Notice (optional) - indicates that the note continues on the next page.

The Rich Text Editor allows you to modify note separators. Use API from the table below to access and edit a separator.

API Description
NoteCollection.HasSeparator Indicates whether notes have the specified separator type.
NoteCollection.BeginUpdateSeparator Initiates the update session of the specified separator type and gives access to its content (the SubDocument object). If the separator doesn’t exist, the method call creates a new separator.
SubDocument.Delete() Removes all or part of the separator content. Use the SubDocument.Range property to obtain the entire separator content. The SubDocument.CreateRange() method allows you to specify a range and delete the content partially.
SubDocument.AppendText()
SubDocument.InsertText()
Adds the specified text.
SubDocument.BeginUpdateCharacters()
SubDocument.EndUpdateCharacters()
Initiates the update session and provides access to CharacterProperties for the specified range.
NoteCollection.EndUpdateSeparator() Finalizes the separator update.

The code sample below shows how to change the footnote separator so it appears as follows:

IMAGE

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

static void EditSeparator(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Check whether the footnotes already have a separator:
    if (document.Footnotes.HasSeparator(NoteSeparatorType.Separator))
    {
        //Initiate the update session:
        SubDocument noteSeparator = 
        document.Footnotes.BeginUpdateSeparator(NoteSeparatorType.Separator);

        //Clear the separator range:
        noteSeparator.Delete(noteSeparator.Range);

        //Append a new text:
        noteSeparator.AppendText("***");

        //Change the separator color:
        CharacterProperties characterProperties = 
        noteSeparator.BeginUpdateCharacters(noteSeparator.Range);
        characterProperties.ForeColor = System.Drawing.Color.Blue;
        noteSeparator.EndUpdateCharacters(characterProperties);

        //Finalize the update:
        document.Footnotes.EndUpdateSeparator(noteSeparator);
    }
}

Note

The Rich Text Editor has no user interface elements to edit footnote or endnote separators.

Convert Notes

In Code

Use methods from the table below to convert notes:

Member Description
Note.Convert Convert a footnote to an endnote or vice versa. A note is added to the end of the corresponding collection.
NoteCollection.Convert Converts all footnotes to endnotes and vice versa. Notes are added to the end of the corresponding collection.
NoteCollection.Swap() Swaps footnotes with endnotes.
using DevExpress.XtraRichEdit.API.Native;

private void ConvertNotes(Document document)
{
    document.LoadDocument("FirstLook.docx");

    //Convert the third footnote to an endnote:
    document.Footnotes[2].Convert();

    //Convert all endnotes to footnotes:
    document.Endnotes.Convert();

    //Uncomment the line below to swap notes:
    //document.Endnotes.Swap();
}

From the User Interface

Right-click a footnote or endnote and click Convert to Endnote or Convert to Footnote to convert a note.

convert notes context menu

Invoke the Footnote and Endnote dialog dialog and click Convert to open the Convert Notes dialog. This dialog includes three conversion options:

  • all footnotes to endnotes
  • all endnotes to footnotes
  • both ways (swap footnotes and endnotes)

convert notes dialog

Change Note Appearance

In Code

You can specify footnote and endnote options for each document section. The Section.FootnoteOptions provides access to the footnote options, the Section.EndnoteOptions property retrieves the endnote options.

Format

The NumberingFormat, StartNumber, and RestartType properties allow you to change the note reference format. If the RestartType property is set to NoteRestartType.NewSection or NoteRestartType.NewPage , the StartNumber property value is ignored.

The code sample below shows how to change the format of notes:

IMAGE

richEditControl.LoadDocument("Document.docx");
Document document = richEditControl.Document;
foreach (Section section in document.Sections)
{
    EndnoteOptions endnoteOptions = section.EndnoteOptions;
    endnoteOptions.NumberingFormat = NumberingFormat.CardinalText;
    endnoteOptions.StartNumber = 3;

    FootnoteOptions footnoteOptions = section.FootnoteOptions;
    footnoteOptions.NumberingFormat = NumberingFormat.UpperRoman;
    footnoteOptions.StartNumber = 5;
}

Location

Use the Document.EndnotePosition property to specify the endnote location. You can place endnotes at the end of the document or at the end of each section.

The FootnoteOptions.Position property allows you to specify one of following footnote locations:

The code sample below shows how to place endnotes at the end of each section and footnotes below text:

richEditControl.LoadDocument("Document.docx");
Document document = richEditControl.Document
document.EndnotePosition = EndnotePosition.EndOfSection;

foreach (Section section in document.Sections)
{
    section.FootnoteOptions.Position = FootnotePosition.BelowText;
}

Layout

Use FootnoteOptions.ColumnCount property to divide footnotes into columns.

Note

The ColumnCount property is ignored when a document is displayed in the RichEditControl. However, you can set this property in code and save its value to a file for further processing in Microsoft Word or other word processing applications.

The code sample below shows how to split footnotes into multiple columns:

richEditControl.LoadDocument("Document.docx");
Document document = richEditControl.Document;

foreach (Section section in document.Sections)
{
    section.FootnoteOptions.ColumnCount = 3;
}

From the User Interface

The Footnotes dialog box launcher invokes the Footnote and Endnote dialog. Options in this dialog allow users to specify note location, layout, and format.

invoke dialog

footnote and endnote dialog

This dialog is also available from the context menu.

invoke from context menu

Remove a Note

In Code

Use one of the following methods to delete a note:

The code sample below shows how to remove the first footnote and all endnotes with custom marks:

static void RemoveNotes(Document document)
{
    document.LoadDocument("Documents//Grimm.docx");

    //Remove first footnote:
    document.Footnotes.RemoveAt(0);


    //Remove all endnotes with custom marks:
    for (int i = document.Endnotes.Count - 1; i >= 0; i--)
    {
        if (document.Endnotes[i].IsCustom)
            document.Endnotes.Remove(document.Endnotes[i]);
    }
}

From the User Interface

Delete the note reference to remove a footnote or endnote. Right-click the note and click Go to Footnote or Go to Endnote to locate the reference.

notes context menu