Add an Endnote to Word in 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 programmatically add an endnote to a existing Word docume…


This content originally appeared on DEV Community and was authored by carlwils

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 programmatically add an endnote to a existing Word document using Free Spire.Doc for Java.

Import Jar Dependency

Method 1: Download the free library 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.

<repositories>
   <repository>
      <id>com.e-iceblue</id>
      <name>e-iceblue</name>
      <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>e-iceblue</groupId>
      <artifactId>spire.doc.free</artifactId>
      <version>5.1.0</version>
   </dependency>
</dependencies>

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
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Moon.docx");

        //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
        textRange.getCharacterFormat().setFontName("Arial");
        textRange.getCharacterFormat().setFontSize(13f);
        textRange.getCharacterFormat().setTextColor(Color.RED);

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

Endnote


This content originally appeared on DEV Community and was authored by carlwils


Print Share Comment Cite Upload Translate Updates
APA

carlwils | Sciencx (2022-04-20T02:27:43+00:00) Add an Endnote to Word in Java. Retrieved from https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/

MLA
" » Add an Endnote to Word in Java." carlwils | Sciencx - Wednesday April 20, 2022, https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/
HARVARD
carlwils | Sciencx Wednesday April 20, 2022 » Add an Endnote to Word in Java., viewed ,<https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/>
VANCOUVER
carlwils | Sciencx - » Add an Endnote to Word in Java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/
CHICAGO
" » Add an Endnote to Word in Java." carlwils | Sciencx - Accessed . https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/
IEEE
" » Add an Endnote to Word in Java." carlwils | Sciencx [Online]. Available: https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/. [Accessed: ]
rf:citation
» Add an Endnote to Word in Java | carlwils | Sciencx | https://www.scien.cx/2022/04/20/add-an-endnote-to-word-in-java/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.