Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I embed a PowerPoint presentation into a WPF application without opening another window?

Currently I have a WPF application in C#, but I'm finding it to be incredibly difficult to find any useful ways to embed a PowerPoint presentation into my window.

One solution I found here: Embedding a Powerpoint show into a C# application

This solution created the problem of having PowerPoint run in another window, but just display its UI within the WPF application. This meant that when the WPF window was focused, the PowerPoint presentation was not, and stopped playing. There was also the problem of PowerPoint crashing when the window was closed.

Another solution I found was here: http://www.codeproject.com/Articles/118676/Embedding-PowerPoint-presentation-player-into-a-WP

The solution was popular, but I found it difficult to work with. I don't know any Win32 programming, OR C++, so I found it extremely hard to modify. I managed to get it to stop displaying a second copy of the PowerPoint (an intended function in the original project), but I've not yet found a way to automatically open the PowerPoint presentation.

So what I need is a way to cleanly open the PowerPoint presentation automatically and in the background (I don't want the PowerPoint UI to be displayed at any point), and to allow it to run automatically (and not respond to input) while the application is running. It would be wonderful if I could keep it within C# and WPF, and not have to deal with Win32 and C++.

Is this possible? At this point I'm really regretting this project simply because of the PowerPoint integration headaches.

like image 778
Brandon Dusseau Avatar asked Mar 31 '13 03:03

Brandon Dusseau


People also ask

Can PowerPoint be embedded?

Get the embed codeOpen your presentation in PowerPoint for the web. On the File tab of the Ribbon, click Share, and then click Embed. In the Embed box, under Dimensions, select the correct dimensions for the blog or web page. Under Embed Code, right-click the code, click Copy, and then click Close.

Can you run a PowerPoint presentation without PowerPoint?

If you don't have PowerPoint installed on your computer, you can still open and view presentations by using PowerPoint for the web or PowerPoint on your mobile device. If you have Windows 10 on your computer, you can install PowerPoint Mobile to view presentations.


2 Answers

Launching the presentation via the command line with the /s flag will play the slideshow without launching the splash screen.

powerpnt.exe /s c:\path\to\your\presentation.pptx

I would try that in concert with some of the WPF embed solutions you've mentioned or taking a look at this approach.

I know little about WPF, so hopefully someone can provide a better answer incorporating all these pieces.

like image 92
mbreske Avatar answered Oct 16 '22 23:10

mbreske


You could convert your presentation to a video format on-the-fly:

// not tested as I don't have the Office 2010, but should work
private string GetVideoFromPpt(string filename)
{
    var app = new PowerPoint.Application();
    var presentation = app.Presentations.Open(filename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

    var wmvfile = Guid.NewGuid().ToString() + ".wmv";
    var fullpath = Path.GetTempPath() + filename;

    try
    {
        presentation.CreateVideo(wmvfile);
        presentation.SaveCopyAs(fullpath, PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue);
    }
    catch (COMException ex)
    {
        wmvfile = null;
    }
    finally
    {
        app.Quit();
    }

    return wmvfile;
}

And then you would play it with MediaElement:

<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />

public void PlayPresentation(string filename)
{
    var wmvfile = GetVideoFromPpt(filename);
    player.Source = new Uri(wmvfile);
    player.Play();
}

Don't forget to File.Delete(wmvfile) when you're done playing the video!

like image 22
Joulukuusi Avatar answered Oct 17 '22 00:10

Joulukuusi