none
How to export PPT slide as image to MemoryStream in C# RRS feed

  • Question

  • Hello,

    I would like to export a PowerPoint slide as an image directly to a MemoryStream (i.e. without writing to disk, a byte array or other data type stored in memory would work as well). Is there a way to accomplish this? I have the following, but it writes to disk:

        var app = new PowerPoint.Application();
        var pres = app.Presentations.Open( @"c:\users\blah\documents\testpres.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse );

        pres.Slides[ 2 ].Export( "temp.png", "PNG" );

        pres.Close();

        app.Quit();

        using (var fs = new FileStream("temp.png", FileMode.Open))
        {
            using (var ms = new MemoryStream())
            {
    fs.CopyTo( ms );
    var data = ms.ToArray();
    }

    Friday, July 29, 2016 6:26 PM

Answers

  • >>>Is there a way to accomplish this? I have the following, but it writes to disk:

    According to your description, MemoryStream is a representation of bytes that need get from file,memory or binary data in the database. PowerPoint Com Object has not any feature to achieve your requirement.

    So I suggest that you could submit any feed back to PowerPoint UserVoice:

    https://powerpoint.uservoice.com/

    Thanks for your understanding.
    • Proposed as answer by David_JunFeng Monday, August 8, 2016 1:39 AM
    • Marked as answer by David_JunFeng Monday, August 8, 2016 1:39 AM
    Monday, August 1, 2016 2:25 AM
  • Using Spire.Presentation, you could achieve this task through following code

        using (MemoryStream ms=new MemoryStream())
                {
                    Image image = presentation.Slides[i].SaveAsImage();
                    image.Save(ms, ImageFormat.Png);
                }
    

    • Marked as answer by David_JunFeng Tuesday, August 9, 2016 1:21 AM
    Monday, August 1, 2016 8:00 AM

All replies

  • >>>Is there a way to accomplish this? I have the following, but it writes to disk:

    According to your description, MemoryStream is a representation of bytes that need get from file,memory or binary data in the database. PowerPoint Com Object has not any feature to achieve your requirement.

    So I suggest that you could submit any feed back to PowerPoint UserVoice:

    https://powerpoint.uservoice.com/

    Thanks for your understanding.
    • Proposed as answer by David_JunFeng Monday, August 8, 2016 1:39 AM
    • Marked as answer by David_JunFeng Monday, August 8, 2016 1:39 AM
    Monday, August 1, 2016 2:25 AM
  • Using Spire.Presentation, you could achieve this task through following code

        using (MemoryStream ms=new MemoryStream())
                {
                    Image image = presentation.Slides[i].SaveAsImage();
                    image.Save(ms, ImageFormat.Png);
                }
    

    • Marked as answer by David_JunFeng Tuesday, August 9, 2016 1:21 AM
    Monday, August 1, 2016 8:00 AM