This project is read-only.

Insert images into a powerpoint

Sep 11, 2014 at 12:56 PM
Hi all,

I'm currently try to embed an existing image into an existing slide.
So my question is howto "embed" the image to the ppt/media folder? Is this possible by using the libopc?

Another approch would be unzip the pptx copy the image into the folder and zip it. I'm not sure if this is the best solution for my problem.

Any feedback very welcome.
best regards,
Sep 11, 2014 at 1:51 PM
Yes, this is definitely possible with libopc. Here are the high-level steps you will need. I'll assume the image is in a file.
  1. Read the image file from disk into a memory buffer.
  2. Initialize libopc
  3. Open the presentation with opcContainerOpen( fname, etc... ) to get a container (c).
  4. See if the image extension is already registerd with opcExtensionGetType(c, ext ). If not, add it with opcExtensionRegister()
  5. Create the image's part (ip) in the container with opcPartCreate( c, path, etc.. ) where path is like this "/ppt/media/image1.png" (I have powerpoint files so my stuff goes under /ppt).
  6. Create an output stream to write the image bytes into with opcContainerCreateOutputStream( c, ip, compress ). Write the bytes with opcContainerWriteOutputStream(). Close stream with opcContainerClose()
  7. That should get the image into the document. You'll need other steps to add a relation from a part to your new image part. ex. from a slide to the image. Use "" for the relation type. And use opcRelationAdd() to add the relation.
Hope this gets you going,
Marked as answer by a_xel on 9/11/2014 at 7:53 AM
Sep 11, 2014 at 3:24 PM
Hi John,

thank you so much, this perfectly answers my question!

best regards,