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.
O
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.
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!
There is a WPF control called DocumentViewer
.
Document
property of the DocumentViewer.Here is the link to convert office documents (including pptx
) to XPS in C sharp.
XAML
<DocumentViewer Name="myDocumentViewer" Margin="0,0,0,59">
</DocumentViewer>
Bind to the Document
property of the control (Note that ConvertPptxDocToXPSDoc
is the method to convert pptx to xps)
myDocumentViewer.Document = this.ConvertPptxDocToXPSDoc(this.FileName, this.newXPSDocumentName).GetFixedDocumentSequence();
I do not really like it, and I'm not sure this applies to your situation. You would need to have access to the presentation, so much's for sure. It is rather easy and leightweight however.
My basic idea was to somehow embed the powerpoint presentation in html and just use the webbrowser control to display it. There seems to be a number of ways to do that.
I decided to try and save the presentation directly as html, which turned out to be possible (at least for PP2010), albeit the layout could be nicer. Another approach (e.g. the google docs) might produce something nicer. I took the following from this link.
In the Immediate pane, type the following, and then press Enter:
ActivePresentation.SaveAs "<Drive>:\users\<username>\desktop\<filename>.htm", ppSaveAsHTML, msoFalse
Note To save by using the Single File Web Page (*.mht; *.mhtml) file format, replace htm at the end of the file name with mht, and replace ppSaveAsHTML with ppSaveAsWebArchive.
If you export it in htm, you get a lot of additional files, in mht it's just a single file so that suited me better. I'm pretty sure it would also be possible to automate this step in code if you need to go generic with your solution.
To display the html file in a webbrowser control is the easy part, I uploaded it to my dropbox for convenience and just set the source (I'll leave it up there for a few days if you want to have a look at it directly).
As for starting the slideshow immediately, I'll have to look into it some more.
<WebBrowser x:Name="webbrowser" Source="https://dl.dropbox.com/u/27614341/test.mht"/>