Hi,
I use Aspose Word to generate a document via LINQ template. That document is very big (~30-200 pages). So, it has footnote inside and due to business case, 1 footnote number can be reference many times in the document.
So, the problem are:
- The footnotes are duplicated for one pages.
- The footnotes are not well ordering.
I tried to remove the redundant footnote by using this code but not work because after layout.getStartPageIndex is invoked, no change after will be applied to Document.
public static final void removeDuplicateFootnote(LayoutCollector layout, com.aspose.words.Document document,
DocumentBuilder builder) throws Exception {
NodeCollection<?> nodes = document.getChildNodes(NodeType.FOOTNOTE, true);
document.updatePageLayout();
// group footnote with its page.
Multimap<Integer, Footnote> footnotePageMap = ArrayListMultimap.create();
for(com.aspose.words.Node node : nodes.toArray()) {
Footnote footNote = (Footnote)node;
footnotePageMap.put(layout.getStartPageIndex(footNote), footNote);
}
// remove duplicate footnote
for (Entry<Integer, Collection> entry : footnotePageMap.asMap().entrySet()) {
final Multimap<String, Footnote> numberMap = ArrayListMultimap.create();
entry.getValue().forEach(e -> numberMap.put(e.getReferenceMark(), e));
for (Entry<String, Collection> nEntry : numberMap.asMap().entrySet()) {
if (nEntry.getValue().size() > 1) {// perform distinct modify number.
List footnotes = Lists.newArrayList(nEntry.getValue());
List removeOnes = footnotes.subList(1, footnotes.size());
for (Footnote removeOne : removeOnes) {
removeOne.remove();
}
}
}
}
}
Is it possible to solve above issues? I attached an example file output for your review.example.zip (15.1 KB)
Thanks and Best Regards,
Tu