From f59e02480205c66a50ef41929cef9b29a0fa50e4 Mon Sep 17 00:00:00 2001 From: Abdur Rahman <90972063+Abdurrahman-shaikh@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:44:57 +0530 Subject: [PATCH] [Fix] Handle missing end page in PDF split range (#2816) ## Summary of Changes **What was changed:** - Updated the `handlePart` method to handle cases where the end page is not specified (e.g., '1-'). - The method now defaults to the last page of the PDF, improving the feature's usability. **Why the change was made:** - Users often forget the total page count when splitting PDFs. The new feature ensures that when only the starting page is specified, the range defaults to the last page, preventing errors like `ArrayIndexOutOfBoundsException`. **Any challenges encountered:** - No significant challenges encountered while implementing this feature. **Closes #1576** --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Testing - [x] I have tested my changes locally. --- src/main/java/stirling/software/SPDF/utils/GeneralUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index ff6e334c4..4a359aff2 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -285,7 +285,10 @@ public class GeneralUtils { String[] rangeParts = part.split("-"); try { int start = Integer.parseInt(rangeParts[0]); - int end = Integer.parseInt(rangeParts[1]); + int end = + (rangeParts.length > 1 && !rangeParts[1].isEmpty()) + ? Integer.parseInt(rangeParts[1]) + : totalPages; for (int i = start; i <= end; i++) { if (i >= 1 && i <= totalPages) { partResult.add(i - 1 + offset);