Footnote And Endnote

This example demonstrates how to add footnotes and endnotes to a document.

Footnotes and endnotes both references are placed at the end of the sentence, phrase or quotation in which they appear to minimize the interruption in the flow of your words.

We take a dummy word file to add footnotes and endnotes

After clicking generate button it will launch a word with above choosen version with added end notes and footnotes

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

using OfficeComponent.Word;


namespace OfficeComponent.Samples
{
    class FootnoteAndEndnoteExample : WordExampleBase
    {
        public FootnoteAndEndnoteExample(string commonDataPath, string outputDir)
            : base(commonDataPath, outputDir)
        {

        }

        public FootnoteAndEndnoteExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)
        {

        }

        public override string Execute()
        {
            // Create a new instance of PdfDocument class.
            WordDocument document = new WordDocument();

            AddFootnotes(document);
            AddEndnotes(document);

            string fileName = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + GetExtension(SaveAsFormat));
            // Save the document.
            document.Save(fileName, SaveAsFormat);

            // Close the document.
            document.Close();


            return fileName;
        }

        void AddFootnotes(WordDocument document)
        {
            Section section = document.AddSection();

            Paragraph para = section.AddParagraph();
            TextRange text = para.AppendText("Footnote Demo");
            para.ApplyStyle(StyleIdentifier.Title);

            section.AddParagraph();
            section.AddParagraph();
            para = section.AddParagraph();
            Footnote footnote = new Footnote(document);
            footnote = para.AppendFootnote(FootnoteType.Footnote);
            footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;

            //Insert Text into the para
            para.AppendText("OfficeComponent").CharacterFormat.Bold = true;
            para = section.AddParagraph();
            para.ParagraphFormat.HorizontalAlignment = OfficeComponent.Word.HorizontalAlignment.Center;
            para.AppendPicture(Image.FromFile(CommonDataPath + "\\Logo.gif"));

            para = footnote.TextBody.AddParagraph();
            para.AppendText("OfficeComponent specializes in developing .NET tools and libraries for Windows developers " +
                            "and providing custom software development and consulting services. Building on its expertise " +
                            "in networking development and Microsoft technologies, OfficeComponent helps customers build competitive " +
                            "applications on their markets.");

            // Set Footnote number format.
            document.FootnoteNumberFormat = FootEndNoteNumberFormat.Arabic;

            // Set Footnote position
            document.FootnotePosition = FootnotePosition.PageBottom;
        }

        void AddEndnotes(WordDocument document)
        {
            Section section = document.AddSection();

            Paragraph para = section.AddParagraph();
            para.AppendText("Endnote Demo");
            para.ApplyStyle(StyleIdentifier.Title);

            section.AddParagraph();
            section.AddParagraph();
            para = section.AddParagraph();
            Footnote footnote = new Footnote(document);
            footnote = para.AppendFootnote(FootnoteType.Endnote);
            footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;

            //Insert Text into the para
            para.AppendText("OfficeComponent Word").CharacterFormat.Bold = true;
            para = section.AddParagraph();
            para.ParagraphFormat.HorizontalAlignment = OfficeComponent.Word.HorizontalAlignment.Center;
            para.AppendPicture(Image.FromFile(CommonDataPath + "\\OfficeComponentWord.gif"));

            para = footnote.TextBody.AddParagraph();
            string content;
            using (StreamReader reader = new StreamReader(CommonDataPath + "\\OfficeComponentWord.txt"))
            {
                content = reader.ReadToEnd();
            }
            para.AppendText(content);

            // Set Endnote numbering format.
            document.EndnoteNumberFormat = FootEndNoteNumberFormat.LowerCaseRoman;
            document.RestartIndexForEndnote = EndnoteRestartIndex.DoNotRestart;

            // Set Endnote position.
            document.EndnotePosition = EndnotePosition.EndOfSection;
        }

    }

}
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text

Imports OfficeComponent.Word


Namespace OfficeComponent.Samples
	Friend Class FootnoteAndEndnoteExample
		Inherits WordExampleBase
		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String)
			MyBase.New(commonDataPath, outputDir)

		End Sub

		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String, ByVal xmlFile As String)
			MyBase.New(commonDataPath, outputDir, xmlFile)

		End Sub

		Public Overrides Function Execute() As String
			' Create a new instance of PdfDocument class.
			Dim document As New WordDocument()

			AddFootnotes(document)
			AddEndnotes(document)

			Dim fileName As String = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & GetExtension(SaveAsFormat))
			' Save the document.
			document.Save(fileName, SaveAsFormat)

			' Close the document.
			document.Close()


			Return fileName
		End Function

		Private Sub AddFootnotes(ByVal document As WordDocument)
			Dim section As Section = document.AddSection()

			Dim para As Paragraph = section.AddParagraph()
			Dim text As TextRange = para.AppendText("Footnote Demo")
			para.ApplyStyle(StyleIdentifier.Title)

			section.AddParagraph()
			section.AddParagraph()
			para = section.AddParagraph()
			Dim footnote As New Footnote(document)
			footnote = para.AppendFootnote(FootnoteType.Footnote)
			footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript

			'Insert Text into the para
			para.AppendText("OfficeComponent").CharacterFormat.Bold = True
			para = section.AddParagraph()
			para.ParagraphFormat.HorizontalAlignment = OfficeComponent.Word.HorizontalAlignment.Center
			para.AppendPicture(Image.FromFile(CommonDataPath & "\Logo.gif"))

			para = footnote.TextBody.AddParagraph()
			para.AppendText("OfficeComponent specializes in developing .NET tools and libraries for Windows developers " & "and providing custom software development and consulting services. Building on its expertise " & "in networking development and Microsoft technologies, OfficeComponent helps customers build competitive " & "applications on their markets.")

			' Set Footnote number format.
			document.FootnoteNumberFormat = FootEndNoteNumberFormat.Arabic

			' Set Footnote position
			document.FootnotePosition = FootnotePosition.PageBottom
		End Sub

		Private Sub AddEndnotes(ByVal document As WordDocument)
			Dim section As Section = document.AddSection()

			Dim para As Paragraph = section.AddParagraph()
			para.AppendText("Endnote Demo")
			para.ApplyStyle(StyleIdentifier.Title)

			section.AddParagraph()
			section.AddParagraph()
			para = section.AddParagraph()
			Dim footnote As New Footnote(document)
			footnote = para.AppendFootnote(FootnoteType.Endnote)
			footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript

			'Insert Text into the para
			para.AppendText("OfficeComponent Word").CharacterFormat.Bold = True
			para = section.AddParagraph()
			para.ParagraphFormat.HorizontalAlignment = OfficeComponent.Word.HorizontalAlignment.Center
			para.AppendPicture(Image.FromFile(CommonDataPath & "\OfficeComponentWord.gif"))

			para = footnote.TextBody.AddParagraph()
			Dim content As String
			Using reader As New StreamReader(CommonDataPath & "\OfficeComponentWord.txt")
				content = reader.ReadToEnd()
			End Using
			para.AppendText(content)

			' Set Endnote numbering format.
			document.EndnoteNumberFormat = FootEndNoteNumberFormat.LowerCaseRoman
			document.RestartIndexForEndnote = EndnoteRestartIndex.DoNotRestart

			' Set Endnote position.
			document.EndnotePosition = EndnotePosition.EndOfSection
		End Sub

	End Class

End Namespace