Visual Studio Developer Center >
Visual Studio Forums
>
Visual Studio Tools for Office
>
How to embed html img into word document?
How to embed html img into word document?
- Ok, I would like to take a very easy route here in generating a word report and avoid having to use inline shapes to insert images. I am generating a report and the result is an html file. i.e.
Using the word object model I would like to open that html file, embed the image(s) and save the file as a .docx. I know this functionality exists in some form, because when I open the html file above in Word 2007, an option becomes available to embed the image via:<html> <head></head> <body> <img src = "anImage.jpg"/> </body> </html><br/>
"Office button" > "Prepare" >"Edit Links to Files".
My question is, how do I programmatically access the "Edit Links to Files" functionality? Or does another method exist that will achieve the same result?
Answers
- Hi Clayton
If I understand you correctly, you want to make sure all the images brought into the document with the HTML file are embedded, rather than linked?
The possibilities depend to a certain extent on the version of Word involved, and whether Word interprets the images as members of the Shapes or InlineShapes collection.
From you message, I infer that this is Office 2007. It's not clear whether the images are in the Shapes or InlineShapes collection, but both objects of both collections have a LinkFormat property that returns a LinkFormat object. This object has a BreakLink method which will embed the graphic. But I urge you to read the BreakLink object topic in the object model Help file to understand how to use it correctly.
Cindy Meister, VSTO/Word MVP- Marked As Answer byclayton.tye Wednesday, November 04, 2009 8:34 PM
All Replies
- Hi Clayton
If I understand you correctly, you want to make sure all the images brought into the document with the HTML file are embedded, rather than linked?
The possibilities depend to a certain extent on the version of Word involved, and whether Word interprets the images as members of the Shapes or InlineShapes collection.
From you message, I infer that this is Office 2007. It's not clear whether the images are in the Shapes or InlineShapes collection, but both objects of both collections have a LinkFormat property that returns a LinkFormat object. This object has a BreakLink method which will embed the graphic. But I urge you to read the BreakLink object topic in the object model Help file to understand how to use it correctly.
Cindy Meister, VSTO/Word MVP- Marked As Answer byclayton.tye Wednesday, November 04, 2009 8:34 PM


