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);
}
}
This content originally appeared on DEV Community and was authored by carlwils
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.