8

I am creating power point 2007 files using the openxml. I am able to add slides, shapes, text and manipulate them to create custom reports. However, I can not find an example on how to dynamically load an image into my power points. In principle I imagine that it would involve adding the image as a resource and then adding a reference to that resource. Any example code would be great help.

Thank you.

Avitus
  • 15,640
  • 6
  • 43
  • 53

1 Answers1

7

You will first need to add an ImagePart to your SlidePart like this:

ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, "rId3");

The "rId3" needs to be the relationshipId that corresponds to your image that you are adding to the presentation. You could also leave that parameter blank and a default relationship id will be created for you. Next you need to feed that image part the actual image:

imagePart.FeedData(new MemoryStream(photo.ToArray())); 

If you are still having trouble take a look at these two blog posts. They both show some code mid way down about adding photos to a presentation.

Creating a report presentation based on data

Adding repeating data to PowerPoint

amurra
  • 15,221
  • 4
  • 70
  • 87