Word文档新增页脚,提示添加失败

您好,我当前使用的aspose 版本是23.6,在对文档添加页脚的时候,SDK抛出异常:Cannot insert a node of this type at this location. 请问是什么问题导致的呢,该如何解决?
代码如下所示:
String path = “/Users/songyexiang/Desktop/test/原始.docx”;
Document document = new Document(path);
Section section = document.getSections().get(0);
HeaderFooter headerFooter = new HeaderFooter(document, HeaderFooterType.FOOTER_PRIMARY);
section.getHeadersFooters().add(headerFooter);
//将内容添加到页脚
headerFooter.appendChild(new Run(document, “Page 1”));
document.save(“/Users/songyexiang/Desktop/test/页码.docx”);

word 文档:
原始.docx (15.5 KB)

@songyassen 这是因为您试图在页脚添加新的 Run,但没有段落。像这样修改代码就可以得到结果:

Document document = new Document("input.docx");
Section section = document.getSections().get(0);
HeaderFooter headerFooter = new HeaderFooter(document, HeaderFooterType.FOOTER_PRIMARY);
section.getHeadersFooters().add(headerFooter);
headerFooter.appendParagraph("Page 1");
document.save("output.docx");