How to save each slide as PNG image?

Hi,Support:

Is there any method to save each slide as png/jpg image with given WxH based on Vb.Net?
for example:
PPT.Slides(0).save(SavePath & “\Slide0.png”,SaveFormat.Png,Width,Height,Quality=80).
or
PPT.save(SavePath & “\Slide0.png”,SlideIndex, SaveFormat.Png,Width,Height,Quality=80).
Or Save each slides as serial image like this:
PPT.save(SavePath & “\Slide{index}.png”,SaveFormat.Png,Width,Height,Quality=80).

How to work it out?

PS: My method is to save ppt as pdf, and then export each pdf page as image.

Thanks for your help.

@ducaisoft,
Thank you for the query. You can save slides as PNG images as shown below:

Dim bitmap = presentation.Slides(0).GetThumbnail(New Size(720, 540))
bitmap.Save(outputFilePath, ImageFormat.Png)

More examples (C#): Convert PowerPoint PPT and PPTX to JPG
API Reference (C#): Slide Methods

Thank you very much.
This can save slide as single image. But there is a bug for this method, that is to say: All the texts in the slide will miss after the slide is saved as image by this method.
How to fix it, Or how the work it out perfectly. Maybe only work it out by converting as pdf and then saving pdf page as image?

And another question is that: how to know the filesize of the PPT object in memory before save it as local ppt file?
That is to say:
PPT.save(OutFile)
Fs=Filelen(OutFile)
The above is the normal way to get the filesize of a file.

Now I want to get the filesize of the PPT object like this:
Fs=PPT.objectFilesize
Or
Fs=PPT.MemorySize

Doess the apit support this function?

@ducaisoft,

Could you please share a code example and presentation file to investigate this case?

Unfortunately, there is no such possibility to know the exact file size before saving the presentation to a file, but you can use the next workaround to estimate the size:

Dim stream = New MemoryStream()
Dim presentation = New Presentation()
presentation.Save(stream, SaveFormat.Pptx)
Console.WriteLine(stream.Length.ToString() + " bytes")
  1. Sample PPTx file for investigating the bug.
    Test.zip (931.4 KB)
    Code to save slide as image based on VB.net v21.4.
    DIm PPT as new presentaton(sFile)
    Dim W As Integer, H As Integer
    W = PPT.SlideSize.Size.Width
    H = PPT.SlideSize.Size.Height
    Dim bitmap = PPT.Slides(0).GetThumbnail(New System.Drawing.Size(W, H))
    On Error Resume Next
    bitmap.Save(AppPath & “\Png.png”, System.Drawing.Imaging.ImageFormat.Png)
    bitmap.Dispose()
    bitmap = Nothing

  2. presentation.Save(stream, SaveFormat.Pptx) will throw exception and then stream.Length is 0,what’s wrong?

@ducaisoft,

Unfortunately, I have not managed to reproduce the problem. Please specify the version of the operating system on which the code example was run.

Could you share a comprehensive code example causing the problem, please?

I run it on Win10 dll v21.4 Vb.net.
I do not know what’s wrong about the dll or my OS or computer.
Now the filesize of outputs are all 0 when running PPT.Save(Output,SaveFormat.PPTX). a few month ago, the method PPT.Save and the dll works normally.
What’s wrong this new issuue?

=====
Dim Stream As IO.MemoryStream
Dim Fs1 As Long
Stream = New IO.MemoryStream()
If PPTx Then
On Error Resume Next
PPT.Save(Stream, Global.Aspose.Slides.Export.SaveFormat.Pptx)
Else
On Error Resume Next
PPT.Save(Stream, Global.Aspose.Slides.Export.SaveFormat.Ppt)
End If
Fs1 = Round(Stream.Length / 1024 / 1024, 2)
'Here the value of Fs1 is always 0 and throw an exception. Maybe my OS or computer is corrupted?

======
On Error Resume Next
Dim layout As Global.Aspose.Slides.ILayoutSlide = PPT.LayoutSlides.Add(PPT.Masters(0), Global.Aspose.Slides.SlideLayoutType.Blank, “Blank”)
If layout Is Nothing Then
layout = PPT.LayoutSlides.GetByType(Global.Aspose.Slides.SlideLayoutType.Blank)
End If
Dim NewPPT As New Global.Aspose.Slides.Presentation()
Dim slide As Global.Aspose.Slides.ISlide = NewPPT.Slides.AddEmptySlide(layout)
NewPPT.Slides.AddEmptySlide(layout)
NewPPT.Save(OutFile, Global.Aspose.Slides.Export.SaveFormat.Pptx)
'Here the filesize of OutFile is always 0 and no blank slide was added. What’s wrong.

@ducaisoft,

Unfortunately, I have still not managed to reproduce the problem. Please share more information on how to reproduce the issue and a screenshot of the exception stack trace.

When you add the empty slide to the new presentation, you cannot use the layout from the other presentation directly. First, you must clone the layout as shown below:

Dim clonnedLayout = NewPPT.LayoutSlides.AddClone(layout)

Then you can use the cloned layout. You can comment out the error suppression to see an exception.
Documents: Clone Slides, Slide Layout, Slide Master