com.aspose.pdf.exceptions.IndexOutOfRangeException(21.2)

When doing pdf Split To Chunks Aspose we are getting IndexOutOfRangeException.Below is the code we are not seeing this error in Aspose.PDF 21.1.

Code :

public static List pdfSplitToChunksAspose(String imageFileIn, String outputDir, int maxPageCount) {
Logger.Log(“pdfSplitToChunksAspose Start”);

	Document pdfDocument = new Document(imageFileIn);
	int pageCount = pdfDocument.getPages().size();
    ElasticApm.currentSpan().setLabel("PageCount", pageCount);

	List<String> outputFiles = new ArrayList<>();
	Document currentDocument = new Document();
	int currentPageCount = 0;
	for (int i = 1; i <= pageCount; i++) {
		currentDocument.getPages().add(pdfDocument.getPages().get_Item(i));

		currentPageCount++;
		if (currentPageCount == maxPageCount) {
			String tmpOutFile = "tmp_" + outputFiles.size() + ".pdf";
			String tmpOutPath = Paths.get(outputDir, tmpOutFile).toString();
			currentDocument.save(tmpOutPath);
			outputFiles.add(tmpOutPath);

			currentDocument = new Document();
			currentPageCount = 0;
		}
	}

	if (currentPageCount > 0) {
		String tmpOutFile = "tmp_" + outputFiles.size() + ".pdf";
		String tmpOutPath = Paths.get(outputDir, tmpOutFile).toString();
		currentDocument.save(tmpOutPath);
		outputFiles.add(tmpOutPath);
	}
	Logger.Log("pdfSplitToChunksAspose Done");
	return outputFiles;
}

Error :

class com.aspose.pdf.exceptions.IndexOutOfRangeException: At most 4 elements (for any collection) can be viewed in evaluation mode.
com.aspose.pdf.ADocument.lf(Unknown Source)
com.aspose.pdf.PageCollection.lf(Unknown Source)
com.aspose.pdf.PageCollection.get_Item(Unknown Source)
com.stormed.common.utils.ImageUtils.pdfSplitToChunksAspose(ImageUtils.java:645)
com.stormed.common.utils.ImageUtils.pdfSplitToSinglePageAspose(ImageUtils.java:670)
com.stormed.production.ProductionMain.(ProductionMain.java:106)
com.stormed.production.common.ProductionBuilder.run(ProductionBuilder.java:27)
com.stormed.proxy.AppRunner.run(AppRunner.java:18)
com.stormed.proxy.ProxyMain.runApp(ProxyMain.java:245)
com.stormed.proxy.ProxyMain.lambda$0(ProxyMain.java:121)
java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
java.util.concurrent.FutureTask.run(FutureTask.java)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

EPIQ INDIA Health Insurance Benefits Manual - 2021.pdf (1.0 MB)

@Vamsi_452

The exception seems related to the evaluation version limitation of the API. It looks like you are using the API without a valid license OR your existing license does not support 21.2 version. Please verify and use a valid or 30-day free temporary license and let us know if issue still persists.

Thanks @asad.ali With upgrade Aspose.pdf 21.3 version we are not seeing this issue.

@Vamsi_452

We are pleased to know that your issue has been resolved. Please keep using our API and feel free to create a new topic in case you need any assistance.