@priyanga,
Thanks for sharing the detail. Perhaps, you are not using the DSMT4 method and extract contents code correctly. Please use DSMT4 method to remove the equations (shapes). This method works without any issue at our end. After removing the shape, please use the same code shared with you earlier to extract the shapes.
In case you are using older version of Aspose.Words, we suggest you please upgrade to the latest version of Aspose.Words for Java 17.8.
We have tested the scenario using following code example and have not found the shared issue. Please check the output document. output documents.zip (2.1 MB)
DSMT4(MyDir + "FeifeiShen-REVISE-2017_input.docx");
/** SECTION D START **/ int i = 1;
Document interimdoc = new Document(MyDir + "FeifeiShen-REVISE-2017_input.docx");
NodeCollection shapes_otherimg = interimdoc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable<Shape>) shapes_otherimg) {
if (shape.hasImage() && shape.getParentParagraph().getNextSibling() != null
&& shape.getParentParagraph().getNextSibling().getNodeType() == NodeType.PARAGRAPH) {
ArrayList nodes1 = ExtractContents.extractContent(shape.getParentParagraph(), shape.getParentParagraph(), true);
ExtractContents.generateDocument(interimdoc, nodes1).save(MyDir + "output"+i+".docx");
Paragraph fig = (Paragraph) shape.getParentParagraph();
/**
* REMOVAL OF NODE(START,END) FROM SOURCE WORD DOC START
**/
shape.getParentParagraph().insertBefore(new BookmarkStart(interimdoc, "Image_" + i), shape);
fig.appendChild(new BookmarkEnd(interimdoc, "Image_" + i));
i++;
for (Bookmark bookmark : interimdoc.getRange().getBookmarks()) {
if (bookmark.getName().startsWith("Image_")) {
bookmark.setText("");
}
}
}
}