Hi,
We are using ASPOSE Words version 9.5.0.0 to replace smart tags with images. If the smart tag is in a table then the image is not properly displaying in the replaced document.
Here is the code snippet which we are using.
Dictionary smartTagDictionary = new Dictionary();
smartTagDictionary.Add("PropertyPhoto.FullSize2", @"c:\P2.jpeg");
smartTagDictionary.Add("PropertyPhoto.FullSize1", @"c:\P1.JPG");
Aspose.Words.Document doc = new Aspose.Words.Document(@"c:\testtemplate.doc");
doc.Range.Replace(new Regex("<<(.*?)>>"), new SmartTagReplaceEvaluator(smartTagDictionary), true);
doc.Save(@"C:\testtemplate-replaced.doc");
public class SmartTagReplaceEvaluator: IReplacingCallback
{
private Dictionary _smartTagDictionary;
public SmartTagReplaceEvaluator(Dictionary SmartTagDictionary)
{
_smartTagDictionary = SmartTagDictionary;
}
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
string tag = e.Match.Value;
string smartTagValue = _smartTagDictionary[tag.Replace("<>", string.Empty).Trim()];
if (!string.IsNullOrEmpty(smartTagValue) && (tag.Contains("Photo"))
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Aspose.Words.Document);
builder.MoveTo(e.MatchNode);
builder.InsertImage(smartTagValue);
}
else
{
e.Replacement = smartTagValue;
}
// Signal to the replace engine to do nothing because we have already done all what we wanted.
return ReplaceAction.Replace;
}
}
Please find the attached zip file containing source document, sample images and replaced document. Please look in to this issue.
Thanks,
-Balaji