From 688e01d70dbee1f19bf08e30044f59582b8e2493 Mon Sep 17 00:00:00 2001 From: Saidul Arefin <37913873+sadi10@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:29:11 +0600 Subject: [PATCH] fixed colorspace array exception (#1925) * fixed colorspace array exception * used lsf4j logger instead of prntln * removed unnecessary comment --- .../api/misc/ExtractImagesController.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java index 266fbd35..3dff43e8 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java @@ -90,22 +90,35 @@ public class ExtractImagesController { // Iterate over each page for (int pgNum = 0; pgNum < document.getPages().getCount(); pgNum++) { PDPage page = document.getPage(pgNum); - int pageNum = document.getPages().indexOf(page) + 1; - // Submit a task for processing each page Future future = executor.submit( () -> { - extractImagesFromPage( - page, - format, - filename, - pageNum, - processedImages, - zos, - allowDuplicates); - return null; + // Use the page number directly from the iterator, so no need to + // calculate manually + int pageNum = document.getPages().indexOf(page) + 1; + + try { + // Call the image extraction method for each page + extractImagesFromPage( + page, + format, + filename, + pageNum, + processedImages, + zos, + allowDuplicates); + } catch (IOException e) { + // Log the error and continue processing other pages + logger.error( + "Error extracting images from page {}: {}", + pageNum, + e.getMessage()); + } + + return null; // Callable requires a return type }); + // Add the Future object to the list to track completion futures.add(future); }