Wraping node with a bookmark


I would like to use Aspose Words java to go through a document and put bookmarks around nodes of the specific type. Currently my solution involves using document builder:

bookmarkName = “Shape”;

Unfortunately, above does not give me desired effect. The bookmark is placed BEFORE the node. What I would like to have is that bookmark starts at the beginning of the node and ends at its end. I couldn’t find a method which would move builders’ cursor to the end of the node.
Could you please help me with that?



Please ZIP and attach your simplified input Word document and your expected document showing the desired output here for our reference. You can create expected document by using MS Word. We will then investigate the scenario on our end and provide you code to achieve the same by using Aspose.Words.

Thank you for your reply, here are the samplesSamples.zip (1.5 MB)


Please try using the following code:

Document doc = new Document("D:\\Temp\\Samples\\Input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

int i = 0;
for(Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
    builder.startBookmark("bm_" + i);
    BookmarkEnd bmEnd = builder.endBookmark("bm_" + i);

    shape.getParentNode().insertAfter(bmEnd, shape);



Hope, this helps.

Works perfectly, thank you for your help.