Free Support Forum - aspose.com

How to Get PNG file of all slide of a Presentation

Hello,

What i am currently trying is:

Presentation ppt = new Presentation(new FileInputStream(new File("D:\\Test Slides\\2.ppt")));
for(int i=1;i<ppt.getSlides().size();i++)
{
System.out.println(ppt.getSlides().size());
Slide s = ppt.getSlideByPosition(6);
Image img=s.getThumbnail(500,500); //getting error here
RenderedImage ir = (RenderedImage)img;
File file = new File("c:\\"+i+"1.png");
ImageIO.write(ir, "png", file);

}

Error Message :

Exception in thread "main" java.lang.NegativeArraySizeException
at java.awt.image.DataBufferInt.(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage.(Unknown Source)
at com.aspose.slides.Slide.getThumbnail(SourceFile:1310)
at com.aspose.slides.Slide.getThumbnail(SourceFile:1207)
at SlideToPNG.main(SlideToPNG.java:32)


This message was posted using Aspose.Live 2 Forum

Dear ritwikkum,

Thanks for considering Aspose.Slides.

Please also attach your source presentation.

Sourece code and PPT attached…

I found out the exception is due to you are passing 500, 500 as parameters to Slide.getThumbnail method. I have modified your code like this and it works fine.

BufferedImage img=s.getThumbnail(new Dimension(500,500));

The complete code for getting all the images is this.

Presentation myPresentation=new Presentation(new FileInputStream(new File("D:\\source\\PPT and Source Code\\2.ppt")));

Slides mySlides=myPresentation.getSlides();

for(int index = 1 ; index <= mySlides.getLastSlidePosition() ; ++index)

{

Slide sld=myPresentation.getSlideByPosition(index);

BufferedImage myPic=sld.getThumbnail(new Dimension(500,500));

ImageIO.write(myPic, "png", new File("c:\\out\\" + index+ ".png"));

}

Thanks for your time and consideration…
Actually if you see Slide.getThumbnail(float, float) is also there, so i was directly giving 500,500 as argument