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

Free Support Forum - aspose.com

How can i Insert image to defined position?

hi Miklovan,

I want to insert an image to my documents. but i dont know image position in document. Users could be put image tag to everywhere of the document.

Simply users write in document tag. and then i will find tag then i will remove it and insert an image instead of tag.

how can i do this?

thanks for care

Ahmet Demirel

The easiest way to do this is using document range replacement with replace evaluator.

Here is a sample code:

private void IncludeImage()

{

Document doc = Open("Doc1.doc");

doc.Range.Replace(new Regex(@"\"), new ReplaceEvaluator(IncludeImageEvaluator), false);

SaveShow(doc, "Doc1 Out.doc");

}

private ReplaceAction IncludeImageEvaluator(object sender, ReplaceEvaluatorArgs e)

{

DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);

builder.MoveTo(e.MatchNode);

builder.InsertImage("Aspose.Words.gif");

// Eraze "" text.

e.Replacement = "";

// commit replacement

return ReplaceAction.Replace;

}

Best regards,

thanks but when I compile with Aspose Words 6.4.0.0, an error has been come out.

DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document); //Error line

Hi

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

Thanks for your inquiry. Use the following code:

// Create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

Best regards.

Can someone translate this to VB? There is no “ReplaceEvaluator” available.

Hello

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

Thanks for your request. There were a few breaking changes to the API in version 9.2/9.3 You can find full details of these changes in the migration article:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-migrate-to-aspose-words-9-2-or-higher.html

ReplaceEvaluator delegate replaced with the IReplacingCallback Interface.

Please see the following link to find an example:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.ireplacingcallback.html

Best regards,