Discussions

Ask a Question
Back to All

Issues while trying to convert a PPT Stream into JPG

Hello. I'm using the C# client to convert an uploaded .PPTX file (I've got the bytes in MemoryStream) into list of JPG files. I get an error when I call the convertApi.ConvertAsync(...) method. The error in accurately states that the stream is empty when in fact it isn't. When I attempted using the same code to convert an html to pdf file, it worked just fine. It doesn't feel like the issue is on my side. Below is the code I'm using.

I've confirmed multiple times that the MemoryStream that is fed into this method is loaded the the bytes for the .PPTX file. Nonetheless, I still get the Exception stating that the MemoryStream is empty. I appreciate any help solving this issue.



public static async Task<string> Convert(MemoryStream pptxFileData)
    {
        try
        {
            var convertApi = new ConvertApi("MySecret");
            var convertPPTXToJPG = await convertApi.ConvertAsync("ppt", "jpg", 
                                            new ConvertApiFileParam(pptFileData, "test.ppt"),                                               new ConvertApiParam("PageRange", "1")
                );
            
            ConvertApiFiles jpgSlide = convertPPTXToJPG.Files.First();
            if (jpgSlide != null)
            {
                return jpgSlide.Url.ToString();
            }
            return null;
        }
        catch (ConvertApiException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
}