Hi,
What is the best way to programmatically insert an image in a word document?
The best information I have found is at https://docs.aspose.com/words/net/working-with-images/
But, I get an error when trying to do something like this.
First, I am unsure about the Image:XXX mail merge field.
I have just created a field like this: { MERGEFIELD Image:myimagename \* MERGEFORMAT}
Is that the right way to do it?
So, I don’t really have any other mail merge fields for now, but I included two others for good measure: { MERGEFIELD myfirstfield \* MERGEFORMAT}{ MERGEFIELD mysecondfield \* MERGEFORMAT}
In my code I have
Private Sub mysub()
Dim myworddoc = New Aspose.Words.Document("myworddoc.doc")
Dim names = New String() {"myfirstfield", "mysecondfield", "Image:myimagename"}
Dim values = New String() {"First", "Second", "Third"}
AddHandler myworddoc.MailMerge.MergeImageField, AddressOf HandleMyImageMerge
myworddoc.MailMerge.Execute(names, values)
myworddoc.Save("mydoc.pdf")
End Sub
Private Shared Sub HandleMyImageMerge(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeImageFieldEventArgs)
e.ImageFileName = "c:\myimagefile.gif"
End Sub
However, this produces an error when it gets to the myworddoc.MailMerge.Execute line:
“Attempted to copy a by reference attribute ‘4152’, but the attribute does not expose the complex attribute interface.”
What am I doing wrong? Is there a better way to do this?
Thanks.