As you may already know, the DevExpress Word Processing API and Rich Text Editor (WinForms and WPF) can now process footnotes and endnotes. Documents with footnotes/endnotes can also be printed and exported to PDF.
The new Note API allows you to execute the following actions:
- Manage existing footnotes/endnotes
- Create new footnotes/endnotes
- Edit footnote/endnote separators
- Change footnote/endnote appearance
Manage Existing Notes
You can access existing footnotes/endnotes, edit content and delete them when necessary.
The following code sample edits a footnote:
static void EditFootNote(RichEditDocumentServer wordProcessor)
{
wordProcessor.LoadDocument("Documents//Grimm.docx");
Document document = wordProcessor.Document;
//Access the first footnote:
SubDocument footnote = document.Footnotes[0].BeginUpdate();
//Exclude the reference mark and the space after it
//from the edit range:
DocumentRange footnoteTextRange =
footnote.CreateRange(footnote.Range.Start.ToInt() + 2, footnote.Range.Length
- 2);
//Clear the range:
footnote.Delete(footnoteTextRange);
//Append new text:
footnote.AppendText("the text is removed");
//Finalize the update:
document.Footnotes[0].EndUpdate(footnote);
}
Create New Notes
You can create new footnotes/endnotes with a regular or custom reference mark.
static void InsertEndnotes(RichEditDocumentServer wordProcessor)
{
wordProcessor.LoadDocument("Document.docx");
Document document = wordProcessor.Document;
//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 to 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");
}
Edit Note Separators
You can access and edit footnote and endnote separators. Our word processing components support the following separator types:
- Separator - separates footnotes/endnotes from the main text.
- Continuation Separator - separates the main text from footnotes/endnotes that continue from the previous page.
- Continuation Notice - indicates that the footnote/endnote continues on the next page.
The following code clears the footnote separator:
static void EditSeparator(RichEditDocumentServer wordProcessor)
{
wordProcessor.LoadDocument("Document.docx");
Document document = wordProcessor.Document;
//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);
//Finalize the update:
document.Footnotes.EndUpdateSeparator(noteSeparator);
}
}
Change Note Appearance
You can change note location on a page and reference mark format.
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
wordProcessor.LoadDocument("Document.docx");
Document document = wordProcessor.Document;
//Show endnotes at the end of each section:
document.EndnotePosition = EndnotePosition.EndOfSection;
foreach (Section section in document.Sections)
{
//Change footnote reference format:
EndnoteOptions endnoteOptions = section.EndnoteOptions;
endnoteOptions.NumberingFormat = NumberingFormat.CardinalText;
endnoteOptions.StartNumber = 3;
//Change endnote reference format and display it below text:
FootnoteOptions footnoteOptions = section.FootnoteOptions;
footnoteOptions.NumberingFormat = NumberingFormat.UpperRoman;
footnoteOptions.StartNumber = 5;
footnoteOptions.Position = FootnotePosition.BelowText;
}
}
Complete code sample projects are available on GitHub:
Limitations
Our current footnote/endnote implementation ships with the following limitations:
- No user interface elements to insert and remove notes. This is on our ToDo list and we are working hard to deliver it in our upcoming release cycle.
- Notes split across multiple columns are displayed in a single column.