5
votes

I'm working with a template document that uses CustomXmlBlocks as placeholders to place tables and other information. I need to be able to place an image into one of these blocks somehow... even if it is placed into a run first.

The images come back from the database in a dataset as a byte array (.bmp format ultimately).

I was trying to do something like this just to see if I could even get the image to show up in the document but to no avail:

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Bmp);
MemoryStream imageStream = new MemoryStream(imgData); //imgData is the byte array

imagePart.FeedData(imageStream);

I keep thinking there has to be an easy way to just take the byte stream and place it into the document but I haven't been able to find any examples anywhere. Do I now need to do something else with that imagePart?

1

1 Answers

1
votes

Yes, you do need to do something else with the imagePart; you need to add an image structure (either an old VML w:pict or a graphic) to your main document part which refers to it. See How to: Insert a Picture into a Word Processing Document

Alternatively, you can add it to a CustomXML part, and suck it in using a picture content control.