none
Using Open XML and C#, how can I convert PowerPoint Slides to PNG files? RRS feed

  • Question

  • Currently via Microsoft.Office.Interop.PowerPoint.dll in a C# application I convert PowerPointSlides to PNG files with the code below. In a hosted environment I will lack the ability to install the dll in the GAC. How can I, using Open XML and C#, convert PowerPoint Slides to PNG files?

    PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Open2007(FILE);
    foreach (PowerPoint.Slide pptSlide in pptPresentation.Slides)
    {
       pptSlide.Export(NEWNAME, "PNG", 1024, 768);
    }
    Friday, November 13, 2009 3:58 PM

Answers

  • OpenXML SDK is for creating/editing documents which base on Open XML format, not competent for this task.


    Z.J.
    • Marked as answer by SR1995 Monday, February 1, 2010 5:11 PM
    Tuesday, November 17, 2009 5:30 AM

All replies

  • OpenXML SDK is for creating/editing documents which base on Open XML format, not competent for this task.


    Z.J.
    • Marked as answer by SR1995 Monday, February 1, 2010 5:11 PM
    Tuesday, November 17, 2009 5:30 AM
  • Jun is correct. That being said, I would like to learn more about your scenario. Why do you need to generate PNGs of the slides?


    Zeyad Rajabi (MS)
    Monday, November 23, 2009 10:54 PM
  • I cant speak for the OP, but in our software we would use this feature extensively. 

    Mainly because in our sharepoint product we offer the ability to view a generated report in the browser. To accomplish this our software generates the report, and then outputs to HTML. Our HTML output is not 100% pixel perfect.

    So if we had the ability to convert docx, xlsx, pptx, to an image, the result the user saw in the browser would be more true to the original file.

    Is this possible without having office on the server ? Or is it possible using word/excel services ? Is there a way to make word/excel services work with pptx documents ?
    Thursday, February 11, 2010 1:38 AM
  • In our scenario we show a preview of the word document to the end user, before she opens it. We have about 3000 word document templates. When a word template gets changed, we create a preview and but it into our VB-application with the link to the template.

    What we like to have is the option to open a word template with open xml framework and save it as a png, without needing to run Word. At the moment we are using Word (save as PDF) und Acrobat (save as PNG), since the quality is an issue (resolution).

    Cheers Harry

    Tuesday, June 1, 2010 7:27 AM
  • Hi Harry,

    As mentioned by Jun, Open XML SDK doesn't support this functionality, you could try Word Automation Services which might help.

    Thanks,

    Lu

    Wednesday, June 2, 2010 2:24 AM
  • Thankx Lu, that's right. The hope is, that MS may see that this would be a feature we are looking for.

    I found the following utilising Word Automation:

    Application wordApplication = new Application();
    Document wordDocument = wordApplication.Documents.Open("test.doc");
    // Create a meta file using the byte array returned from EnhMetaFileBits
    byte[] emfData = (byte[])wordApplication.ActiveDocument.ActiveWindow.Panes[1].Pages[1].EnhMetaFileBits;
    System.IO.MemoryStream ms = new System.IO.MemoryStream(emfData);
    Metafile mf = new Metafile(ms);
    mf.Save(@"test.png");
    wordDocument.Close();
    wordApplication.Quit();
    

    I also think, that SharePoint 2010 Word Automation Services (is this what you mean) will provide some Word functions, not sure about saving to png.

    Cheers Harry

    Wednesday, June 2, 2010 5:10 AM