- Home
- Forum
- ASP.NET MVC - EJ 2
- How to generate thumbnail image for a PPTX file in C#?
How to generate thumbnail image for a PPTX file in C#?
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;
}
}
}
}
SIGN IN To post a reply.
1 Reply
KC
Karthikeyan Chandrasekar
Syncfusion Team
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
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
LU Luis
- Feb 17, 2019 12:18 AM UTC
- Feb 18, 2019 03:41 PM UTC