Aspose Words Range - Paste method

Hello,
I have a document which has few bookmarks and one of the bookmark is Signature(Image). I loop thru all the bookmarks and replace all the text on bookmark and would like to update the Signature bookmark with an Image. How can I do this with Aspose?
Actually I am trying to convert code which was originally using MSWord interop and replacing same with Aspose.Words. We have working code as below with MSWord.

For each lBookmark in doc.Formfields
 Dim wdRange as Word.Range
 Clipboard.SetImage(lObjSystemDrawingImage)
 wdRange = lBookmark.Range
 wdRange.Paste
Next

I tried to replace same code with Aspose but did not find wdRange.Paste method. Is there any work around to insert image inside of FormField?
Thanks,
Vinay Hattarki

Hello
Thanks for your request. Aspose.Words provides functionality for easy moving nodes inside document. For example you can try using DocumentBuilder to insert image into the bookmart. Please see the following link to learn more about DocumentBuilder:
https://docs.aspose.com/words/net/document-builder-overview/
https://docs.aspose.com/words/net/programming-with-documents/
Hope this helps.
Best regards,

I looked at the links and did not find any specific example which actually inserts image inside form field. I saw DocumentBuilder.InsertImage and did utilize same but did not get desired results.

 Dim lobjDocBuilder As Aspose.Words.DocumentBuilder = New DocumentBuilder(lwdDocument)
 lobjDocBuilder.MoveToBookmark("DIGITAL_SIGNATURE")
 lobjDocBuilder.InsertImage(VBOUser.DigitalSignature, Aspose.Words.Drawing.RelativeHorizontalPosition.Margin, 10, _
 Aspose.Words.Drawing.RelativeVerticalPosition.Margin, 80, _
 VBOUser.DigitalSignature.Width, VBOUser.DigitalSignature.Height, Drawing.WrapType.TopBottom)

This does try to position the image but how should I get 10 and 80 which is Top and Left. Also this image is outside of FormField and its not part of Form Field.
In situation this gets moved to begning of the document.
Is there any way I could have bookmark contain Image.
Thanks,
Vinay Hattarki

Hello
Thank you for your interest in Aspose.Words. Could you please attach your input and expected output documents here for testing? I will check them and provide you more information.
Best regards,

Please look at attached document. You will find various form fields and how its being replaced programatically with respective text. You will also see field called " Digital Signature " at the bottom, I would like to get the output similar to attached document thru code where you see the image is exactly in front of Digital Signature and after the form field.
You will see form field empty, if I can get image inside of form field that would be nice or at least it should be near by form field inserted.
Digital Signature form field could be anywhere in the document and it does not have any fixed location.
thanks,
Vinay Hattarki.

Hello
Thank you for additional information. May I suggest you more simply way to achieve what you need? I think it will be better to use mail merge feature of Aspose.Words. Please see the following simple code:

Document doc = new Document("C:\\Temp\\AsposeDoc.doc");
doc.MailMerge.Execute(new string[]
    {
        "FirmName",
        "AssociatedFirstName",
        "AssociatedNameTitle",
        "SignatuteImage"
    },
    new object[]
    {
        "Test Firm Name",
        "Andrey",
        "Mr",
        "C:\\Temp\\img.jpg"
    });
doc.Save("C:\\Temp\\out.doc");

Also I have attached the modified template and the output document.
In case of using Mail Merge, you can use pre-defined template for generating your document.
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
Best regards,

Thanks for you help.
Unfortunately we cannot use mail merge and it has to be thru Form Field only. We have huge set of code and various forms working fine with form fields. We have been using form field for quite long time now and changing everything to mail merge just for Digital Signature is not acceaptable.
Our system works in such way that, user himself creates these templates by inserting Form Fields and these are populated later thru whats in database. This has been long time process that cannot be changed.
Do we have any work around for this thru form field? or Any way to get the exact position of "Digital Signature " form field location so that I could use InsertImage with Absolute position.
Any help appreciated
Thanks,

Hello
Thank you for additional information. In this case please try using the following code:

// Open document
Document doc = new Document("C:\\Temp\\AsposeDoc.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get Pagent Paragraph of formfield DIGITAL_SIGNATURE1
Paragraph paragraph = doc.Range.FormFields["DIGITAL_SIGNATURE1"].ParentParagraph;
builder.MoveTo(paragraph);
builder.InsertImage("C:\\Temp\\img.jpg");
doc.Save("C:\\Temp\\out.doc");

Best regards,

Thanks a million, it works fine and positions the image where needed.
Though it keeps the original bookmark as empty vertical box which is easily visible and somehwat confusing.
I tried to assign empty result to bookmark(Digital_Signature) and that did not help.
Any idea how to get rid of empty form field box? Please review attached document, now I have three different Digital Signature fields on the document.
Thanks,

Hello
Thanks for your request. I think you can try using the following line of code:

doc.Range.FormFields["DIGITAL_SIGNATURE1"].Result = " ";

or

doc.Range.FormFields["DIGITAL_SIGNATURE1"].Result = "";

Best regards,

I think the issue was with empy space " ", I fixed that. Appreciate all your help to get this resolved.
Thank you

Hi
Please let us know in case of any issues, we will be glad to help you.
Best regards,