@Saranya_Sekar,
Please try using the following code and see these output documents output.zip (2.6 MB).
Document doc = new Document("D:\\temp\\Anchored_Images (2)\\Anchored_Images.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
int i = 1;
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
if (shape.getParentParagraph() == null ||
shape.getParentParagraph().getChildNodes().getCount() == 1 ||
shape.getAncestor(NodeType.TABLE) != null ||
shape.getShapeType() == ShapeType.TEXT_BOX) {
} else {
Document newDoc = (Document) doc.deepClone(false);
newDoc.removeAllChildren();
newDoc.ensureMinimum();
Shape importedShape = (Shape) newDoc.importNode(shape, true);
importedShape.setWrapType(WrapType.NONE);
importedShape.setHorizontalAlignment(HorizontalAlignment.CENTER);
importedShape.setVerticalAlignment(VerticalAlignment.CENTER);
importedShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
importedShape.setRelativeHorizontalPosition(RelativeVerticalPosition.PAGE);
newDoc.getFirstSection().getBody().getFirstParagraph().appendChild(importedShape);
builder.moveTo(shape);
builder.getFont().setColor(Color.red);
builder.write(" <Inline-Img>Inline-Img" + i + "</Inline-Img> ");
shape.remove();
newDoc.save("D:\\temp\\Anchored_Images (2)\\shape_" + i + ".docx");
}
i++;
}
doc.save("D:\\temp\\Anchored_Images (2)\\out.docx");