IndexOutOfRangeException on ImagePlacementAbsorber

Hi Team,

We are getting a “com.aspose.pdf.exceptions.IndexOutOfRangeException​” for certain pdf files when we are trying to check if the pdf has any images in it. Below is the stacktrace. Could you please let us know what is the cause for the issue and how this can be fixed. Below is the stack trace and the code snippet.

We are using AWS Java.al2 linux env​
Aspose version : 24.6

“Error”: “com.aspose.pdf.exceptions.IndexOutOfRangeException”,
“Cause”: "{"errorMessage":"At most 4 elements (for any collection) can be viewed in evaluation mode.","errorType":"com.aspose.pdf.exceptions.IndexOutOfRangeException","stackTrace":["com.aspose.pdf.ADocument.lf(Unknown Source)","com.aspose.pdf.ADocument.lI(Unknown Source)","com.aspose.pdf.ADocument.lI(Unknown Source)","com.aspose.pdf.XFormCollection.lI(Unknown Source)","com.aspose.pdf.XFormCollection.get_Item(Unknown Source)","com.aspose.pdf.ImagePlacementAbsorber.lf(Unknown Source)","com.aspose.pdf.ImagePlacementAbsorber.lf(Unknown Source)","com.aspose.pdf.ImagePlacementAbsorber.lf(Unknown Source)","com.aspose.pdf.ImagePlacementAbsorber.lI(Unknown Source)","com.aspose.pdf.ImagePlacementAbsorber.visit(Unknown Source)","com.aspose.pdf.Page.accept(Unknown Source)","com.aspose.pdf.Page$accept.call(Unknown Source)","org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)","org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)","org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)","com.tr.cns.documenttotext.service.PDFFileFormatService$_hasImage_closure3.doCall(PDFFileFormatService.groovy:52)","sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)","sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)","sun.reflect.DelegatingMethodAccessorImpl.invoke(Delegat

Code snippet:

document.pages.any {
it.accept(imagePlacementAbsorber)

boolean isImageFound = !imagePlacementAbsorber.imagePlacements.empty
log.debug(“Scanning a page number ${count++} on images. An image ${isImageFound ? ‘is’ : ‘is not’} found.”)

isImageFound
}

Thanks !

@treutersaspose

Looks like you are using the API without any license. Please try to set the license before using any method of the API and if issue still persists, please let us know.

You can obtain a free temporary license for 30-days to evaluate the API in case you don’t have one already.

We do have a valid license and other docuements are processing without this failure …Only for few documents we are seeing this issue. Can you let us know in what scenarios this exception is thrown.

@treutersaspose

Such exception can only be seen if license has not been set correctly. There may be some routine in your program or code that bypasses the license setting lines while using ImagePlacementAbsorber. There could be a case of multi-threading as well if you are setting license in different thread which has not been yet executed.