We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conversion of PPTX to image throws ArrayIndexOutOfBoundsException

Hi,

I am using Aspose.slides version 2.3.0.
I get following exception while trying to convert pptx file to image:
java.lang.ArrayIndexOutOfBoundsException: 109
at com.aspose.slides.obfuscated.wb.try(SourceFile:111)
at com.aspose.slides.obfuscated.wb.do(SourceFile:134)
at com.aspose.slides.obfuscated.bl.new(SourceFile:58)
at com.aspose.slides.obfuscated.bl.(SourceFile:47)
at com.aspose.slides.obfuscated.ap.do(SourceFile:34)
at com.aspose.slides.obfuscated.ap.(SourceFile:30)
at com.aspose.slides.Presentation.(SourceFile:513)
at com.unica.thumnailgenerator.ConvertPPTToImage.convert(ConvertPPTToImage.java:26)

public class ConvertPPTToImage implements IConvertor{
private static final UALogger LOG = (UALogger)UALogger.getLogger(ConvertPPTToImage.class);

private String outputFileName;
public boolean convert(String pptFileName, String outputFileName){

Presentation pres;
this.outputFileName = outputFileName;

try {
pres = new Presentation(new FileInputStream(new File(pptFileName)));

int count = 1;

Slide slide = pres.getSlideByPosition(count);
BufferedImage image=slide.getThumbnail(new Dimension(125,125));
ImageIO.write(image,outputFileName.substring(outputFileName.indexOf(".")+1), new File(outputFileName));


} catch (Exception e) {
LOG.error(e);
return false;
}
return true;
}

public File getOutput() {
return new File(outputFileName);
}

}


Line causing trouble is : pres = new Presentation(new FileInputStream(new File(pptFileName)));

I have attached the pptx file also which generated this exception.

I am working with jdk 1.5 version on windows platform.
Please let me know if you need any more details.

Thanks,
Suprita

Dear Supitra,

I have worked with the presentation file shared by you and have been able to access the presentation with no exception and have generated the slide thumbnail successfully. I have used the code sample given on this link. For your kind reference, I have attached the generated slide thumbnails. The rendering of charts is currently not supported so it's appearing as a pink box in the generated thumbnail. An issue with ID 18998 has already been created in our issue tracking system for providing chart rendering support. This thread has also been linked with the same issue, so that you may be automatically notified, once the issue is resolved.

We are sorry for your inconvenience,

Which version of aspose slides did you use?
I am still getting the exception.

On standalone application I get following exception:
java.lang.OutOfMemoryError: Java heap space
at com.aspose.slides.obfuscated.cj.char(SourceFile:84)
at com.aspose.slides.obfuscated.cj.new(SourceFile:56)
at com.aspose.slides.obfuscated.cj.(SourceFile:47)
at com.aspose.slides.obfuscated.bn.do(SourceFile:34)
at com.aspose.slides.obfuscated.bn.(SourceFile:30)
at com.aspose.slides.Presentation.do(SourceFile:170)
at com.aspose.slides.Presentation.(SourceFile:522)
at com.unica.thumnailgenerator.ConvertPPTToImage.convert(ConvertPPTToImage.java:26)


Dear Supitra,

I have used Aspose.Sliddes for Java 2.3.0 for accessing the presentation, which is available here. I have used the code snippet available on this link. Please feel free to share if the problem still persist. One suggestion that I would like to give is that you may please increase the heap size as well before execution.

Thanks and Regards,

Thanks for your response.
I increased the heapsize and now I get a different exception:

java.lang.NegativeArraySizeException
at com.aspose.slides.obfuscated.kk.do(SourceFile:34)
at com.aspose.slides.obfuscated.cj.try(SourceFile:65)
at com.aspose.slides.obfuscated.cj.new(SourceFile:60)
at com.aspose.slides.obfuscated.cj.(SourceFile:47)
at com.aspose.slides.obfuscated.bn.do(SourceFile:34)
at com.aspose.slides.obfuscated.bn.(SourceFile:30)
at com.aspose.slides.Presentation.do(SourceFile:170)
at com.aspose.slides.Presentation.(SourceFile:522)
at com.unica.thumnailgenerator.ConvertPPTToImage.convert(ConvertPPTToImage.java:26)

Thanks.

Dear Suprita,

It's quite surprising to know that the same things are executing fine on my end and unfortunately failing to do so, on your end. Can you please share the information about the JDK version that you are using along with Aspose.Slides for Java version. I am using jdk1.6.0_21 with Aspose.Slides for Java 2.3.0.

Thanks and Regards,

I am using jdk 1.5.0_22.

any updates?

Dear Suprita,

I am arranging the mentioned JDK 1.5.0_22 to reproduce your scenario. Meanwhile, I may suggest you to kindly try the JDK 1.6.0_21 as well on your end. Hopefully, upgrading to mentioned version may solve the issue.

Thanks and Regards,

My whole application is certified to work on jdk 1.5.
I can not upgrade to jdk 1.6.

Hi,

I am trying to arrange jdk 1.5 and will verify the presentation on that. I will share with you my findings as soon as I am able to get the mentioned version of jdk. I will appreciate your patience for that.

Thanks and Regards,

Any updates?
I need the fix urgently.

Hi,

I have discussed the issue with our development team and it may be potentially an issue in Aspose.Slides for Java. For further investigation and resolution an issue with ID 19139 has been created in our issue tracking system. As soon as some information is received from them, I will share that with you. I have also requested them for an earliest reply. This thread has also been linked with the issue, so that you may be automatically notified, once the issue is resolved.

we are sorry for your inconvenience,

Hi Suprita,

I have revisited your code and have found that you are trying to access the PPTX file using Presentation class object. Please use PresentationEx class object to access the PPTX. Please follow this link to programmer guide section for reference.

Thanks and Regards,

Hi Mudassir,

Thanks for your suggestion, atleast I could get past the exceptions.
However, the thumbnail generated is of 0 bytes and of no use.

I had to add a reference to aspose.metafiles.

Please let me know the next steps.

Thanks,
Suprita

Hi Suprita,

I have worked on the presentation file shared by you and have been successfully able to generate the slide thumbnails. I have used Aspose.Slides for Java 2.3.0. For your kind reference, I have attached the sample code along with the generated images as well. Please also add the reference to Aspose.Metafiles jar file in your project code as well. Hopefully things will work for you.

String savePath="D:\\ppt\\";
PresentationEx Pres=new PresentationEx(savePath+"test2.pptx");
SlideEx slide;

BufferedImage Img;
for(int i=0;i<Pres.getSlides().size();i++)
{
slide=Pres.getSlides().get(i);
Img= slide.getThumbnail(1f,1f);
ImageIO.write(Img, "png", new java.io.File(savePath+"Image" +i+".png"));
ImageIO.write(Img, "jpg", new java.io.File(savePath+"Image" +i+".jpg"));

}

Thanks and Regards,

Hi Mudassir,

Thanks a lot.
That worked for me.
Can we control the dimensions of the image file generated. I require an image of size 125 px by 125 px.

Thanks,
Suprita

Dear Suprita,

Please follow this documentation link for details about SlideEx.getThumbnail() method. You may not set the dimension when you are using getThumbnail() for PPTX. All you can give is the scaling factor. when scaling factor is 1, it means the generated thumbnail will be of same size as original slide. The normal slide size is 720 x 540. In order to get the dimension 125x125 the scale X parameter should by 0.1736 and scale Y 0.23. Please use the following code snippet in your code.

Img= slide.getThumbnail(0.1736f,0.23f);

Thanks and Regards,

The scaling creates the file of right size but the contents are all lost.
It is cutting all the text and I get a blank thumbnail.