tags:

views:

228

answers:

1

Hi,

I have been using Syncfusion DocIO for generating MS Word documents from my .net applications (winforms). So far I have dealt with plain text and it is fairly straightforward to insert text in a word document template where bookmarks serve as reference points for text insertion.

I am navigating the bookmarks using BookmarksNavigator.MoveToBookmark() . Now I need to insert an image at a bookmark but I am at a loss at how to go about it.

Please help...

Thanks.

A: 
private System.Drawing.Image LoadSignature(string sFileName)
{
    string sImagePath = sFileName;
    System.Drawing.Image image = System.Drawing.Image.FromFile(sImagePath);
    return image;
}

private void MergeSignature(WordDocument doc, string sFile, string sBalise)
{
    System.Drawing.Image iSignature = LoadSignature(sFile);
    WordDocument ImgDoc = new WordDocument();
    ImgDoc.AddSection();
    ImgDoc.Sections[0].AddParagraph().AppendPicture(iSignature);

    if (iSignature != null)
    {
        TextSelection ts = null ;
        Regex pattern = new Regex(sBalise);
        ts = doc.Find(pattern);

        if (ts != null)
        {
            doc.ReplaceFirst = true;
            doc.Replace(pattern, ImgDoc, false);
        }
    }
    iSignature.Dispose();
}