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

Free Support Forum - aspose.com

How to extract content from a bookmak and check if it is an image (on multiple images) or a doc fragment

Hi, I need to get the content from a bookmark.
I’ve seen this post: https://forum.aspose.com/t/74740.
This is very useful for me, but the code provided in the post get also the bookmark itself.
How can I exctract only the content inside the bookmark?

And I have another question.
Sometimes the content of my bookmarks can be an image, or multiple image. How can I distinguish if the content is made by images only? Maybe by checking if all the nodes are Shape?

Thank you!

Hi Alessandro,

Thanks for your query. You can get the contents inside the bookmark by using following line of code. Please also read this documentation link.

String contents = doc.Range.Bookmarks["MyBookMark"].Text;

You can distinguish between Image and Paragraph nodes by using following code snippet.

Document doc = new Document(@"d:/MyBookMark.doc");
Bookmark bm = doc.Range.Bookmarks["MyBookMark"];
Node curNode = bm.BookmarkStart.NextSibling;
while (curNode.NodeType != NodeType.BookmarkEnd)
    Node nextNode = curNode.NextPreOrder(doc);
    if (nextNode.NodeType.Equals(NodeType.Shape))
    else if (nextNode.NodeType.Equals(NodeType.Paragraph))
    curNode = nextNode;