How can I deal with footnotes that insert by ZOTERO?

in the test.docx,
test.docx (250.2 KB)

there are footnotes that inserted by some citation management softwares. and when I use code like :

Document document = new Document("src/main/test/com/test/test.docx");
NodeCollection<Footnote> childNodes = document.getChildNodes(NodeType.FOOTNOTE, true);
for (Footnote footnote : childNodes)
{
    Font font = footnote.getFont();
    font.setSuperscript(true);
    for (Paragraph paragraph : footnote.getParagraphs())
    {

        if (paragraph.hasChildNodes())
        {

            String text = paragraph.getText().trim();

            // 如果遇到网页地址类型,设置为“左对齐”
            if (text.replaceAll("\\s+", "").contains("http") ||
                    text.replaceAll("\\s+", "").contains("www"))
            {
                paragraph.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
            }

            NodeCollection<Node> paragraphChildNodes = paragraph.getChildNodes(NodeType.ANY, true);

            paragraph.getRuns().clear();
            // 脚注内容和编号之间空一个英文字符
            Run space = new Run(document, " ");
            space.getFont().setName("宋体");
            Run run = new Run(document, text.trim());

            paragraph.getRuns().add(space);
            paragraph.getRuns().add(run);

            paragraph.getParagraphFormat().setKeepTogether(true);


        }
    }
}

document.save("src/main/test/result.docx");

and the result turns to

so, how can i deal with these ? I just want to show the original content.

@Madecho Could you please attach your sample input, current and expected output documents here for our reference? We will check the documents and provide you more information. What is the actual purpose of your code? As I ca see you simply change some properties of paragraph and runs. For this is is not require to replace the original Run nodes in the paragraph.

Also, in your code you use paragraph.getText(), when this method is used the returned text also contains field codes and other invisible marks. If you need to get the displayed text try using paragraph.toString(SaveFormat.TEXT)

1 Like

Yes attach sample !

@devorabrenton Thank you for additional information. But if possible, could you please attach a simplified input, current and expected output documents.
Also, please answer the questions from the above post and try the suggestion made above.