DEV Community


Posted on

Remove footnote from Word document Using Java

In my previous article, I have introduce how to use Free Spire.Doc for Java to insert footnote to word document. Now, this article will share how to remove footnote from word document programmatically.

Method 1: Download Free Spire.Doc for Java 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.

Enter fullscreen mode Exit fullscreen mode

Sample Code

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

public class RemoveFootnote {
    public static void main(String[] args) throws Exception {

        //Load the Sample Word document.
        Document document = new Document();

        Section section = document.getSections().get(0);

        //Traverse paragraphs in the section and find the footnote
        for (int j = 0; j < section.getParagraphs().getCount(); j++) {
            Paragraph para = section.getParagraphs().get(j);
            int index = -1;
            for (int i = 0, cnt = para.getChildObjects().getCount(); i < cnt; i++) {
                ParagraphBase pBase = (ParagraphBase) para.getChildObjects().get(i);
                if (pBase instanceof Footnote) {
                    index = i;

            if (index > -1)
                //remove the footnote
        document.saveToFile("Removefootnote.docx", FileFormat.Docx);
Enter fullscreen mode Exit fullscreen mode

Discussion (0)