C # MS Office PPT for image conversion

I am starting to program in C # and Windows. I wrote a service that converts a powerpoint file into separate slide images using the method slide.exportthat libraries provide microsoft.office.interop.powerpoint. I can get all the slides, but some of them seem to be broken, and I see "Image cannot be displayed. Memory exceeded"or the like. I thought it was insufficient memory, and then just tried it with ppt with one slide (whose image was broken), and to my horror, I found that one image was also broken.

Am I using the export incorrectly or should pass different arguments, what am I already driving through? I will insert the code below.

Microsoft.Office.Interop.PowerPoint.Application appPpt
    = new Microsoft.Office.Interop.PowerPoint.Application();

Microsoft.Office.Interop.PowerPoint.Presentation objActivePresentation
    = appPpt.Presentations.Open(strFilePath,
                                Microsoft.Office.Core.MsoTriState.msoCTrue,
                                Microsoft.Office.Core.MsoTriState.msoTriStateMixed,
                                Microsoft.Office.Core.MsoTriState.msoFalse);

foreach (Microsoft.Office.Interop.PowerPoint.Slide objSlide
                                                   in objActivePresentation.Slides)
{
    //Names are generated based on timestamp. 
    objSlide.Export(slideName, "PNG", 960, 720);
    objSlide.Export(slideNameMedium, "JPG", 307, 231);
    objSlide.Export(slideNametn, "JPG", 150, 113);
}

I need help here. Thanks in advance.

+3
source share
2

SaveAs. , .....

+5
string imgName = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\Img_{DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss")}";
oSlide.Export(imgName + ".png", "png", 1920, 1080);
0

All Articles