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)