News Category

Remove footnote from Word document in Java

2019-11-11 07:31:26 Written by  support iceblue
Rate this item
(0 votes)

We have already demonstrated how to use Spire.Doc to insert footnote to word document in Java applications. This article will show how to remove footnote from word document in Java.

Firstly, view the sample document with footnotes:

Remove footnote from Word document in Java

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();
        document.loadFromFile("Sample.docx");

        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;
                    break;
                }
            }

            if (index > -1)
                //remove the footnote
                para.getChildObjects().removeAt(index);
        }
        document.saveToFile("Removefootnote.docx", FileFormat.Docx);
    }
}

Effective screenshot after remove the footnote from word document:

Remove footnote from Word document in Java

Additional Info

  • tutorial_title:
Last modified on Tuesday, 31 August 2021 09:21