Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 20, 2022 02:27 am GMT

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 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


Original Link: https://dev.to/carlwils/add-an-endnote-to-word-in-java-2a66

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To