You can add an external image to an word document via a quick parts field.
For a description please see the following answer on superuser.
To realize the described steps programmatically you have to
use an external releationship to include an image from an URL.
Here are the steps to accomplish this:
- Create an instance of the Picture class.
- Add a Shape to specify the style of the picture (width/height).
- Use the ImageData class to specify the ID of the external releationship.
- Add an external releationship to the main document part. Give the external
releationship the same ID you specified in step 3.
The following code just implements the steps described above. The image is added to the
first paragraph in the word document.
using (WordprocessingDocument newDoc = WordprocessingDocument.Open(@"c:\temp\external_img.docx", true))
{
var run = new Run();
var picture = new Picture();
var shape = new Shape() { Id = "_x0000_i1025", Style = "width:453.5pt;height:270.8pt" };
var imageData = new ImageData() { RelationshipId = "rId56" };
shape.Append(imageData);
picture.Append(shape);
run.Append(picture);
var paragraph = newdoc.MainDocumentPart.Document.Body.Elements<Paragraph>().FirstOrDefault();
paragraph.Append(run);
newDoc.MainDocumentPart.AddExternalRelationship(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
new System.Uri("<url to your picture>", System.UriKind.Absolute), "rId56");
}
In the code above I've omitted the code to define the shape type. I advise you to use a
tool like the OpenXML SDK productivity tool
to inspect a word document with an external releationship to an image.