Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add image to powerpoint openxml

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.

like image 820
Avitus Avatar asked May 17 '11 22:05

Avitus


1 Answers

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

like image 97
amurra Avatar answered Oct 15 '22 09:10

amurra