Inserting dynamic image into a dynamicly built text string

I am not sure if this is possible, but I am trying to build a html text string dynamicly where the html will include text and images and then use the builder.inserthtml function. Something like this

dim sb as new stringbuilder
sb.append("**Hello**")
sb.append("image.jpg")
sb.append("*World*")
builder.MoveToBookmark("Bookmark")
builder.InsertHtml(sb.tostring)

I saw that I can pull in an image using but was wondering if it can be done without the image being on a web server.
If this is not possible, is it possible to add a bookmark within the text string that I could later add an image into?

dim sb as new stringbuilder
sb.append("**Hello**")
sb.append(create bookmark in this spot)
sb.append("*World*")
builder.MoveToBookmark("Bookmark")
builder.InsertHtml(sb.tostring)

Thanks

Hi Brad,
Thanks for your inquiry. Yes, you can achieve your requirements by using both approaches. For first scenario, I suggest you please use the Alt property of Image tag in html and set the image data after inserting the html. Please use the Shape.AlternativeText property to identify an image as shown in following code example. Please check the ImageData.SetImage methods from here:
SetImage
Sets the image that the shape displays.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
    "<P align='right'>Paragraph right</P>" +
    "<b>Implicit paragraph left</b>" +
    "<div align='center'>Div center</div>" +
    "<h1 align='left'>Heading 1 left.</h1>");

foreach(Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    if (shape.AlternativeText == "myImg")
    {
        Image Img = Image.FromFile(MyDir + "in.png");
        shape.ImageData.SetImage(Img);
        shape.Height = Img.Height;
        shape.Width = Img.Width;
    }
}
doc.Save(MyDir + "Out.docx");

For second scenario, you can insert bookmark in html as shown in following code snippet. After inserting the html, please use DocumentBuilder.MoveToBookmark method to move the cursor to bookmark and insert the image. Please check the following code example.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
    "<P align='right'>Paragraph right</P>" +
    "<b>Implicit paragraph left</b>" +
    "<div align='center'>Div center</div>" +
    "<h1 align='left'>Heading 1 left.</h1>");
builder.MoveToBookmark("bookmark");
builder.InsertImage(MyDir + "in.png");
doc.Save(MyDir + "Out.docx");

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

Thanks. This works great for what I was trying to do.

Hi Brad,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.