Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Movies from Powerpoint to file in C#

Some Powerpoint presentation contains embedded movies. How to export movies from presentation (or get path to movie file) using C# (VSTO or Oficce COM Api)?

like image 789
ird Avatar asked Feb 14 '11 10:02

ird


People also ask

Can we Export PowerPoint to video file?

On the File menu, select Save to ensure all your recent work has been saved in PowerPoint presentation format (. pptx). Click File > Export > Create a Video. (Or, on the Recording tab of the ribbon, click Export to Video.)


2 Answers

Here is simple demo to do this:

don't forget to add reference to the PowerPoint COM API (Microsoft PowerPoint 12.0 Object Library).

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

then you can get the movies path like this

    private void button1_Click(object sender, EventArgs e)
    {
        PowerPoint.Application app = new PowerPoint.Application();
        app.Visible = Office.MsoTriState.msoTrue;
        //open powerpoint file in your hard drive
        app.Presentations.Open(@"e:\my tests\hello world.pptx");

        foreach (PowerPoint.Slide slide in app.ActivePresentation.Slides)
        {
            PowerPoint.Shapes slideShapes = slide.Shapes;
            foreach (PowerPoint.Shape shape in slideShapes)
            {
                if (shape.Type == Office.MsoShapeType.msoMedia &&
                    shape.MediaType == PowerPoint.PpMediaType.ppMediaTypeMovie)
                {
                    //LinkFormat.SourceFullName contains the movie path 
                    //get the path like this
                    listBox1.Items.Add(shape.LinkFormat.SourceFullName);
                    //or use System.IO.File.Copy(shape.LinkFormat.SourceFullName, SOME_DESTINATION) to export them
                }
            }
        }
    }

I hope this will help.

[Edit:]

regarding Steve comment if you want just the embedded movies, you need just to unpack the .pptx file like any other zip file (e.g. using DotNetZip) and look for embedded videos in this path ([PowerPoint_fileName]\ppt\media)

like image 117
Issam Ali Avatar answered Nov 08 '22 05:11

Issam Ali


It is very easy. Extract the file as Zip file using SharpZipLib library, the files will be at ppt\media folder :)

this question will help you:

Programmatically extract embedded file from PowerPoint presentation

And this is the link of sharp-zip-lib:

http://www.icsharpcode.net/opensource/sharpziplib/

like image 20
Sawan Avatar answered Nov 08 '22 05:11

Sawan