We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Wraping node with a bookmark

Hello,

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:

builder.moveTo(node);
bookmarkName = “Shape”;
builder.startBookmark(bookmarkName);
builder.endBookmark(bookmarkName);

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?

Thanks,
Miki

@miki00,

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)

@miki00,

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.moveTo(shape);
    builder.startBookmark("bm_" + i);
    BookmarkEnd bmEnd = builder.endBookmark("bm_" + i);

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

    i++;
}

doc.save("D:\\temp\\Samples\\awjava-18.11.docx"); 

Hope, this helps.

Works perfectly, thank you for your help.