Add an Endnote to Word Using Java

Like footnote, the endnote is a supplementary explanation to the main text. It is usually located at the end of the document to list the source of the citation. This article will show you how to add an endnote to Word documents using Free Spire.Doc for Java.

Method 1: Download the free API and unzip it. Then add the Spire.Doc.jar file to your Java application as dependency.

Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.


Sample Code

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.Footnote;
import com.spire.doc.fields.TextRange;

import java.awt.*;

public class AddEndnote {

public static void main(String[] args) {

//Create a Document object
Document doc = new Document();

//Load the sample Word file

//Get the first section
Section section = doc.getSections().get(0);

//Get the specific paragraph to add endnote
Paragraph paragraph = section.getParagraphs().get(3);

//Add an endnote
Footnote endnote = paragraph.appendFootnote(FootnoteType.Endnote);

//Set endnote text
TextRange textRange = endnote.getTextBody().addParagraph().appendText("You can add the necessary endnote here.");

//Set text format of endnote

//Save to file
doc.saveToFile("AddEndnote.docx", FileFormat.Docx_2013);

Sharing Java Code