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

Free Support Forum - aspose.com

Find tag and replace it with image using C#

I have some VB.NET code that opens a Word document as an Aspose.Word.Document, then loops through all the nodes until it finds a certain keyword.

When It finds this keyword it needs to be able to insert an image at that point in the code, but so far I’ve only been able to find code examples that build a word document from scratch using DocumentBuilder, or inserting into the page using absolute coordinates.

Is there a method available that can insert directly to the currently selected node?
I can do this to insert external word documents using the InsertDocument example, just not images.


Thanks for your query. Please use the MoveTo method of DocumentBuilder class. You can move to a node by using MoveTo method. Please also read all method of DocumentBuilder.MoveToXXX.

Use DocumentBuilder to Insert Document Elements
Using DocumentBuilder to Modify a Document Easily

Dim doc As New Document(“c:\DocumentBuilder.doc”)

Dim builder As New DocumentBuilder(doc)



Hope this helps you. Please let us know, If you have any more queries.

Thanks for your help!

In the end, I had to create a temporary document, assign a document builder to it, add the image to that document then add that document to my original document using the InsertDocument function.

Bit awkward, but at least it works :slight_smile:

thanks again


Thanks for your query. You can use a simple replace method to replace such string (keyword) with image. I would suggest you to use IReplacingCallback.

Please follow up the thread where my colleague have share a code snippet to replace string “{{tag}}” with mail merge fields.

The provided code is in C#, but I think there will not be problems to translate it to VB.

I hope this will help. In case of further assistance, please let me know.

A post was merged into an existing topic: Insert image logo into PDF file