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

Free Support Forum - aspose.com

Insert an image

Hi there!

I have an Idatareader which brings me an image's url. I have this:

docBuilder.InsertImage(AppDomain.CurrentDomain.BaseDirectory + dr[9].ToString);

but now I want the image to be pasted on an specific place, with something like this:

doc.Range.Replace(new System.Text.RegularExpressions.Regex("@Image")....

where @Image is set in a field of my Word template.

I don't know how to do this, any help?

Thanks in advance!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I can suggest you two ways to achieve this using Aspose.Words.

You can try using bookmarks inside your document. Please see the following code example:

// Open the document.

Document doc = new Document("in.doc");

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

// Go to bookmark

documentBuilder.MoveToBookmark("Image");

// Insert Image

documentBuilder.InsertImage("Test\img.jpg");

doc.Save("out.doc");

Or you can try using merge fields, in this case you will be able to use MergeImageField event handler to achieve what you need. Please see the following forum thread to learn how to do it during MailMerge:

http://www.aspose.com/community/forums/200599/showing-shapes-images-dynamically/showthread.aspx#200599

Best regards,

Hi again,

It seems it can't get into the bookmark. I get the image out of the template, at the top of it. Any ideas?

Many thanks

Hi

Thanks for additional information. Could you please attach your document and code here for testing? I will check the problem on my side and provide you more information.

Best regards,

Hi again,

My code is something like this:

string fileName = "c:\\Test\\DocTemplateIn.doc";

Document doc = new Document(fileName);

DocumentBuilder docBuilder = new DocumentBuilder(doc);

docBuilder.MoveToBookmark("@Imagen");

docBuilder.InsertImage(AppDomain.CurrentDomain.BaseDirectory + dr[6].ToString()); //dr[6] contains my image's url

doc.Save("c:\\Test\\DocTemplateOut.doc");

And result is attached. Thanks!

Problem solved.

Once I set the license the image went to its place.

Thanks for everything!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

It is perfect, that you already resolved the problem. Please let me know in case of any issues. I will be glad to help you.

Best regards,