We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to generate thumbnail image for a PPTX file in C#?

Thread ID:

Created:

Updated:

Platform:

Replies:

142727 Feb 17,2019 12:18 AM UTC Feb 18,2019 03:41 PM UTC ASP.NET MVC - EJ 2 1
loading
Tags: Presentation
Luis
Asked On February 17, 2019 12:25 AM UTC

Is it possible to generate thumbnails for a pptx file using Syncfusion as oppose to using Aspose?

Here in my generate preview method, I've calculated what the size for each thumbnail should be but it doesn't seem like you can generate thumbnails from the slides like Aspose does.

 public override void GeneratePreview(Stream docStream, IPreviewGenerationContext context)
        {
            docStream.Seek(0, SeekOrigin.Begin);

            var pres = Presentation.Open(docStream);

            if (context.StartIndex == 0)
                context.SetPageCount(pres.Slides.Count);

            int firstIndex;
            int lastIndex;
            var loggedPageError = false;

            context.SetIndexes(pres.Slides.Count, out firstIndex, out lastIndex);

            // calculate size based on the original aspect ratio and the expected image size.
            var sizeF = pres.Slides[0].SlideSize;
            var ratio = Math.Min((float)Common.PREVIEW_WIDTH / sizeF.Width, 
                                 (float)Common.PREVIEW_HEIGHT / sizeF.Height);
            var size = new Size((int)Math.Round(sizeF.Width * ratio),
                                (int)Math.Round(sizeF.Height * ratio));

            for (var i = firstIndex; i <= lastIndex; i++)
            {
                try
                {
                    var slide = pres.Slides[i];

                    // generate image
                    using (var image = slide.GetThumbnail(size)) // Need to be able to generate a thumbnail for each slide.
                    {
                        context.SaveImage(image, i + 1);
                    }
                }
                catch (Exception ex)
                {
                    if (Tools.HandlePageError(ex, i + 1, context, !loggedPageError))
                        return;

                    loggedPageError = true;
                }
            }
        }
    }



Karthikeyan Chandrasekar [Syncfusion]
Replied On February 18, 2019 03:41 PM UTC

Hi Luis,  
We do not have direct support to generate thumbnail image for a PPTX file, but we can achieve it using the below code snippet:  
  
//Load the existing PowerPoint Presentation  
using (IPresentation pptxDoc = Presentation.Open("GettingStarted.pptx"))  
{  
    //Load each slide in PowerPoint  
    foreach (ISlide slide in pptxDoc.Slides)  
    {  
        //Conver the PowerPoint slide to image  
        Image image = slide.ConvertToImage(Syncfusion.Drawing.ImageType.Bitmap);  
  
        //Set the size for image  
        Size size = new Size(200, 200);  
  
        //Create new Bitmap image with spcified size for converted image.  
        Bitmap bitmap = new Bitmap(image, size);  
  
        //Save the image in specified location  
        bitmap.Save(ResolveApplicationOutputPath("/") + "image" + Guid.NewGuid().ToString() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);  
    }  
}  
  
Please find the sample link which will generate the thumbnails in the custom size as you required.  
Please find the KB link which will be used to set the custom resolution and custom size in PowerPoint to Image Conversion.   
Regards, 
Karthikeyan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;