跪拜 Guibai
← All articles
Java

Add, Read, and Delete Word Footnotes and Endnotes from Java

By 用户372157426135 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Automated Java document pipelines can now handle footnotes and endnotes end-to-end, which matters for report generators, thesis tools, and any software that creates or audits Word files with academic annotations.

Summary

Spire.Doc's Java API gives developers direct control over Word footnotes and endnotes: add them, read them, and delete them. Adding a footnote is a two-step process: locate the target text with Document.findString(), then insert a Footnote object after that TextRange via Paragraph.appendFootnote() and getChildObjects().insert(). The same appendFootnote() call creates an endnote when passed FootnoteType.Endnote, though the default position is at the paragraph's end rather than after a keyword.

Reading existing notes uses Document.getFootnotes() and Document.getEndnotes(), each returning a list of Footnote objects whose TextBody holds paragraphs. Inserting a footnote inside a document's body doesn't require touching the footer; Word's footnotes are separate from page footers. Deletion works by removing the Footnote object from its owner paragraph's child objects, iterating backward to avoid index shifts.

The article also flags positioning details: the API places markers at paragraph end by default, so precise placement after a keyword demands find-and-insert logic, and note numbering or location may depend on Word's document settings, not just the code.

Takeaways
— Spire.Doc 14.10.6 from the e-iceblue Maven repository supplies Java APIs for footnotes and endnotes in Word.
— Document.findString() locates target text; the example uses the first match only.
— Paragraph.appendFootnote(FootnoteType.Footnote) creates a footnote; FootnoteType.Endnote creates an endnote.
— The note object must be inserted into the paragraph's child objects at the desired index; the default places it at the paragraph's end.
— getTextBody().addParagraph().appendText() sets note content, and note text formatting is applied separately from the reference marker's font.
— Document.getFootnotes() and Document.getEndnotes() return lists of Footnote objects, each with a TextBody of paragraphs.
— Deleting footnotes requires removing each Footnote from its owner paragraph's child objects, iterating from the end to avoid index shifts.
— The deletion example removes only footnotes; endnotes are left untouched.
Conclusions

The library unifies footnotes and endnotes into a single Footnote class distinguished by an enum, which keeps the API surface small and lets developers build one code path for both.

appendFootnote()'s default behavior places the marker at the paragraph end, so precise placement after a keyword requires extra find-and-insert steps, a reminder that document object placement is not always intuitive.

The warning that endnote and footnote positions depend on Word's document settings means automation must account for layout rules beyond the API's simple insertion to produce correct output.

Concepts & terms
Spire.Doc
A commercial library for reading and manipulating Word documents in Java and .NET, available through e-iceblue's Maven repository.
FootnoteType
An enum in Spire.Doc that distinguishes footnotes (FootnoteType.Footnote) from endnotes (FootnoteType.Endnote) when creating a note object.
TextBody
The container inside a Footnote or Endnote object that holds the note's paragraphs and other content, separate from the main document body.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗