From d9db298bc2c879bfa921bfbabef409438eb31cfa Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Sat, 2 Aug 2025 21:46:26 +0100 Subject: [PATCH 1/9] Add page number input field to split-by-sections tool (UI only) --- app/core/src/main/resources/messages_en_GB.properties | 6 ++++-- .../src/main/resources/templates/split-pdf-by-sections.html | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index f78e80b65..27dde7fcf 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -806,8 +806,8 @@ home.overlay-pdfs.desc=Overlays PDFs on-top of another PDF overlay-pdfs.tags=Overlay home.split-by-sections.title=Split PDF by Sections -home.split-by-sections.desc=Divide each page of a PDF into smaller horizontal and vertical sections -split-by-sections.tags=Section Split, Divide, Customize,Customise +home.split-by-sections.desc=Split the content of specified PDF pages into smaller horizontal and vertical sections. +split-by-sections.tags=Section Split, Divide, Customize, Customise home.AddStampRequest.title=Add Stamp to PDF home.AddStampRequest.desc=Add text or add image stamps at set locations @@ -1586,6 +1586,8 @@ split-by-sections.horizontal.placeholder=Enter number of horizontal divisions split-by-sections.vertical.placeholder=Enter number of vertical divisions split-by-sections.submit=Split PDF split-by-sections.merge=Merge Into One PDF +split-by-sections.pageToSplit=Pages to split (Enter a comma-separated list of page numbers) : +split-by-sections.pageToSplit.placeholder=(e.g. 1,2,6 or 1-10,15-30) #printFile diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index 1f94d8a23..548abe217 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -20,6 +20,11 @@
+
+ + +

From 07b3bfa1f3f123e094e8646c694ed730686d68e5 Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Sun, 3 Aug 2025 23:32:45 +0100 Subject: [PATCH 2/9] Improve input sanitization for split-pdf-by-sections --- .../src/main/resources/templates/split-pdf-by-sections.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index 548abe217..aac54ee8f 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -79,6 +79,12 @@ // Initial draw updateVisualAid(); + + // Removes all whitespace characters (spaces, tabs, newlines) as the user types + document.getElementById('pageToSplit').addEventListener('input', function () { + this.value = this.value.replace(/\s+/g, '');; + }); +
From 1fc40f16c25cc38fb57fa83cd085e119e9a69833 Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Sun, 3 Aug 2025 23:47:13 +0100 Subject: [PATCH 3/9] feat: implement backend support for selective page splitting in Split PDF by Sections --- .../api/SplitPdfBySectionsController.java | 82 ++++++++++++------- .../model/api/SplitPdfBySectionsRequest.java | 6 ++ 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java index c2bbd31b5..7920f6aef 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java @@ -5,7 +5,9 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -33,6 +35,7 @@ import lombok.RequiredArgsConstructor; import stirling.software.SPDF.model.api.SplitPdfBySectionsRequest; import stirling.software.common.service.CustomPDFDocumentFactory; +import stirling.software.common.util.GeneralUtils; import stirling.software.common.util.WebResponseUtils; @RestController @@ -55,13 +58,20 @@ public class SplitPdfBySectionsController { List splitDocumentsBoas = new ArrayList<>(); MultipartFile file = request.getFileInput(); + String pageNumbers = request.getPageNumbers(); PDDocument sourceDocument = pdfDocumentFactory.load(file); + // Split the page order string into an array of page numbers or range of numbers + String[] pageOrderArr = pageNumbers.split(","); + List pageListToSplit = + GeneralUtils.parsePageList(pageOrderArr, sourceDocument.getNumberOfPages(), false); + Set pagesToSplit = new HashSet<>(pageListToSplit); + // Process the PDF based on split parameters int horiz = request.getHorizontalDivisions() + 1; int verti = request.getVerticalDivisions() + 1; boolean merge = Boolean.TRUE.equals(request.getMerge()); - List splitDocuments = splitPdfPages(sourceDocument, verti, horiz); + List splitDocuments = splitPdfPages(sourceDocument, verti, horiz, pagesToSplit); String filename = Filenames.toSimpleFileName(file.getOriginalFilename()) @@ -110,51 +120,61 @@ public class SplitPdfBySectionsController { } public List splitPdfPages( - PDDocument document, int horizontalDivisions, int verticalDivisions) + PDDocument document, int horizontalDivisions, int verticalDivisions, Set pagesToSplit) throws IOException { List splitDocuments = new ArrayList<>(); + int pageIndex = 0; for (PDPage originalPage : document.getPages()) { - PDRectangle originalMediaBox = originalPage.getMediaBox(); - float width = originalMediaBox.getWidth(); - float height = originalMediaBox.getHeight(); - float subPageWidth = width / horizontalDivisions; - float subPageHeight = height / verticalDivisions; + // If current page is not to split, add it to the splitDocuments directly. + if (!pagesToSplit.contains(pageIndex)) { + PDDocument newDoc = pdfDocumentFactory.createNewDocument(); + newDoc.addPage(originalPage); + splitDocuments.add(newDoc); + } else { + // Otherwise, split current page. + PDRectangle originalMediaBox = originalPage.getMediaBox(); + float width = originalMediaBox.getWidth(); + float height = originalMediaBox.getHeight(); + float subPageWidth = width / horizontalDivisions; + float subPageHeight = height / verticalDivisions; - LayerUtility layerUtility = new LayerUtility(document); + LayerUtility layerUtility = new LayerUtility(document); - for (int i = 0; i < horizontalDivisions; i++) { - for (int j = 0; j < verticalDivisions; j++) { - PDDocument subDoc = new PDDocument(); - PDPage subPage = new PDPage(new PDRectangle(subPageWidth, subPageHeight)); - subDoc.addPage(subPage); + for (int i = 0; i < horizontalDivisions; i++) { + for (int j = 0; j < verticalDivisions; j++) { + PDDocument subDoc = new PDDocument(); + PDPage subPage = new PDPage(new PDRectangle(subPageWidth, subPageHeight)); + subDoc.addPage(subPage); - PDFormXObject form = + PDFormXObject form = layerUtility.importPageAsForm( - document, document.getPages().indexOf(originalPage)); + document, document.getPages().indexOf(originalPage)); - try (PDPageContentStream contentStream = - new PDPageContentStream( - subDoc, subPage, AppendMode.APPEND, true, true)) { - // Set clipping area and position - float translateX = -subPageWidth * i; + try (PDPageContentStream contentStream = + new PDPageContentStream( + subDoc, subPage, AppendMode.APPEND, true, true)) { + // Set clipping area and position + float translateX = -subPageWidth * i; - // float translateY = height - subPageHeight * (verticalDivisions - j); - float translateY = -subPageHeight * (verticalDivisions - 1 - j); + // float translateY = height - subPageHeight * (verticalDivisions - j); + float translateY = -subPageHeight * (verticalDivisions - 1 - j); - contentStream.saveGraphicsState(); - contentStream.addRect(0, 0, subPageWidth, subPageHeight); - contentStream.clip(); - contentStream.transform(new Matrix(1, 0, 0, 1, translateX, translateY)); + contentStream.saveGraphicsState(); + contentStream.addRect(0, 0, subPageWidth, subPageHeight); + contentStream.clip(); + contentStream.transform(new Matrix(1, 0, 0, 1, translateX, translateY)); - // Draw the form - contentStream.drawForm(form); - contentStream.restoreGraphicsState(); + // Draw the form + contentStream.drawForm(form); + contentStream.restoreGraphicsState(); + } + + splitDocuments.add(subDoc); } - - splitDocuments.add(subDoc); } } + pageIndex++; } return splitDocuments; diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java index 3a89ab686..2fad48203 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java @@ -10,6 +10,12 @@ import stirling.software.common.model.api.PDFFile; @Data @EqualsAndHashCode(callSuper = true) public class SplitPdfBySectionsRequest extends PDFFile { + @Schema( + description = "Pages to be split by section", + defaultValue = "all", + requiredMode = Schema.RequiredMode.REQUIRED) + private String pageNumbers; + @Schema( description = "Number of horizontal divisions for each PDF page", defaultValue = "0", From 07c5294accfea3da6bd935ddf922ff375bc3681b Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Mon, 4 Aug 2025 11:28:12 +0100 Subject: [PATCH 4/9] feat: implement split modes including presets and custom input Added support for predefined split modes: - Split all except first and last - Split all except first - Split all except last - Split all Also added a custom mode that enables users to specify exact pages to split via input field. --- .../api/SplitPdfBySectionsController.java | 57 +++++++++++++++++-- .../software/SPDF/model/SplitTypes.java | 9 +++ .../model/api/SplitPdfBySectionsRequest.java | 12 ++++ .../main/resources/messages_en_GB.properties | 9 ++- .../templates/split-pdf-by-sections.html | 22 ++++++- 5 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 app/core/src/main/java/stirling/software/SPDF/model/SplitTypes.java diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java index 7920f6aef..9933951c0 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java @@ -33,6 +33,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import stirling.software.SPDF.model.SplitTypes; import stirling.software.SPDF.model.api.SplitPdfBySectionsRequest; import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.util.GeneralUtils; @@ -51,7 +52,8 @@ public class SplitPdfBySectionsController { summary = "Split PDF pages into smaller sections", description = "Split each page of a PDF into smaller sections based on the user's choice" - + " (halves, thirds, quarters, etc.), both vertically and horizontally." + + " which page to split, and how to split" + + " ( halves, thirds, quarters, etc.), both vertically and horizontally." + " Input:PDF Output:ZIP-PDF Type:SISO") public ResponseEntity splitPdf(@ModelAttribute SplitPdfBySectionsRequest request) throws Exception { @@ -59,13 +61,10 @@ public class SplitPdfBySectionsController { MultipartFile file = request.getFileInput(); String pageNumbers = request.getPageNumbers(); + String splitMode = request.getSplitMode(); PDDocument sourceDocument = pdfDocumentFactory.load(file); - // Split the page order string into an array of page numbers or range of numbers - String[] pageOrderArr = pageNumbers.split(","); - List pageListToSplit = - GeneralUtils.parsePageList(pageOrderArr, sourceDocument.getNumberOfPages(), false); - Set pagesToSplit = new HashSet<>(pageListToSplit); + Set pagesToSplit = getPagesToSplit(pageNumbers, splitMode, sourceDocument.getNumberOfPages()); // Process the PDF based on split parameters int horiz = request.getHorizontalDivisions() + 1; @@ -119,6 +118,52 @@ public class SplitPdfBySectionsController { } } + // Based on the mode, get the pages that need to be split and return the pages set + private Set getPagesToSplit(String pageNumbers, String splitMode, int totalPages) { + Set pagesToSplit = new HashSet<>(); + + switch (SplitTypes.valueOf(splitMode)) { + case CUSTOM: + if (pageNumbers == null || pageNumbers.isBlank()) { + throw new IllegalArgumentException("Custom mode requires page numbers input."); + } + String[] pageOrderArr = pageNumbers.split(","); + List pageListToSplit = GeneralUtils.parsePageList(pageOrderArr, totalPages, false); + pagesToSplit.addAll(pageListToSplit); + break; + + case SPLIT_ALL: + for (int i = 0; i < totalPages; i++) { + pagesToSplit.add(i); + } + break; + + case SPLIT_ALL_EXCEPT_FIRST: + for (int i = 1; i < totalPages; i++) { + pagesToSplit.add(i); + } + break; + + case SPLIT_ALL_EXCEPT_LAST: + for (int i = 0; i < totalPages - 1; i++) { + pagesToSplit.add(i); + } + break; + + case SPLIT_ALL_EXCEPT_FIRST_AND_LAST: + for (int i = 1; i < totalPages - 1; i++) { + pagesToSplit.add(i); + } + break; + + default: + throw new IllegalArgumentException("Unsupported split mode: " + splitMode); + } + + return pagesToSplit; + } + + public List splitPdfPages( PDDocument document, int horizontalDivisions, int verticalDivisions, Set pagesToSplit) throws IOException { diff --git a/app/core/src/main/java/stirling/software/SPDF/model/SplitTypes.java b/app/core/src/main/java/stirling/software/SPDF/model/SplitTypes.java new file mode 100644 index 000000000..19c1b5a5b --- /dev/null +++ b/app/core/src/main/java/stirling/software/SPDF/model/SplitTypes.java @@ -0,0 +1,9 @@ +package stirling.software.SPDF.model; + +public enum SplitTypes { + CUSTOM, + SPLIT_ALL_EXCEPT_FIRST_AND_LAST, + SPLIT_ALL_EXCEPT_FIRST, + SPLIT_ALL_EXCEPT_LAST, + SPLIT_ALL +} diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java index 2fad48203..829dd5371 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; +import stirling.software.SPDF.model.SplitTypes; import stirling.software.common.model.api.PDFFile; @Data @@ -16,6 +17,17 @@ public class SplitPdfBySectionsRequest extends PDFFile { requiredMode = Schema.RequiredMode.REQUIRED) private String pageNumbers; + @Schema( + implementation = SplitTypes.class, + description = + "Modes for page split. Valid values are:\n" + + "SPLIT_ALL_EXCEPT_FIRST_AND_LAST: Splits all except the first and the last pages.\n" + + "SPLIT_ALL_EXCEPT_FIRST: Splits all except the first page.\n" + + "SPLIT_ALL_EXCEPT_LAST: Splits all except the last page.\n" + + "SPLIT_ALL: Splits all pages.\n" + + "CUSTOM: Custom split.\n") + private String splitMode; + @Schema( description = "Number of horizontal divisions for each PDF page", defaultValue = "0", diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index 27dde7fcf..e3579ef48 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -1587,7 +1587,14 @@ split-by-sections.vertical.placeholder=Enter number of vertical divisions split-by-sections.submit=Split PDF split-by-sections.merge=Merge Into One PDF split-by-sections.pageToSplit=Pages to split (Enter a comma-separated list of page numbers) : -split-by-sections.pageToSplit.placeholder=(e.g. 1,2,6 or 1-10,15-30) +split-by-sections.pageToSplit.placeholder=(e.g. 1,2,6) +split-by-sections.mode=Mode +split-by-sections.mode.1=Split all except first and last +split-by-sections.mode.2=Split all except first +split-by-sections.mode.3=Split all except last +split-by-sections.mode.4=Split all +split-by-sections.mode.5=Custom. Specify pages to split + #printFile diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index aac54ee8f..8c0e2bb62 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -20,6 +20,16 @@
+
+ + +

From 483d8b812b794898ea4ff680639e1c4eb0502af0 Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Mon, 4 Aug 2025 15:22:12 +0100 Subject: [PATCH 5/9] Fix split mode null crash by defaulting to ALL --- .../api/SplitPdfBySectionsController.java | 34 +++++++++++-------- .../model/api/SplitPdfBySectionsRequest.java | 22 ++++++------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java index 9933951c0..08f1dfeb7 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java @@ -4,10 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -61,10 +58,14 @@ public class SplitPdfBySectionsController { MultipartFile file = request.getFileInput(); String pageNumbers = request.getPageNumbers(); - String splitMode = request.getSplitMode(); + SplitTypes splitMode = Optional.ofNullable(request.getSplitMode()) + .map(SplitTypes::valueOf) + .orElse(SplitTypes.SPLIT_ALL); + PDDocument sourceDocument = pdfDocumentFactory.load(file); - Set pagesToSplit = getPagesToSplit(pageNumbers, splitMode, sourceDocument.getNumberOfPages()); + Set pagesToSplit = + getPagesToSplit(pageNumbers, splitMode, sourceDocument.getNumberOfPages()); // Process the PDF based on split parameters int horiz = request.getHorizontalDivisions() + 1; @@ -119,16 +120,17 @@ public class SplitPdfBySectionsController { } // Based on the mode, get the pages that need to be split and return the pages set - private Set getPagesToSplit(String pageNumbers, String splitMode, int totalPages) { + private Set getPagesToSplit(String pageNumbers, SplitTypes splitMode, int totalPages) { Set pagesToSplit = new HashSet<>(); - switch (SplitTypes.valueOf(splitMode)) { + switch (splitMode) { case CUSTOM: if (pageNumbers == null || pageNumbers.isBlank()) { throw new IllegalArgumentException("Custom mode requires page numbers input."); } String[] pageOrderArr = pageNumbers.split(","); - List pageListToSplit = GeneralUtils.parsePageList(pageOrderArr, totalPages, false); + List pageListToSplit = + GeneralUtils.parsePageList(pageOrderArr, totalPages, false); pagesToSplit.addAll(pageListToSplit); break; @@ -163,9 +165,11 @@ public class SplitPdfBySectionsController { return pagesToSplit; } - public List splitPdfPages( - PDDocument document, int horizontalDivisions, int verticalDivisions, Set pagesToSplit) + PDDocument document, + int horizontalDivisions, + int verticalDivisions, + Set pagesToSplit) throws IOException { List splitDocuments = new ArrayList<>(); @@ -193,12 +197,12 @@ public class SplitPdfBySectionsController { subDoc.addPage(subPage); PDFormXObject form = - layerUtility.importPageAsForm( - document, document.getPages().indexOf(originalPage)); + layerUtility.importPageAsForm( + document, document.getPages().indexOf(originalPage)); try (PDPageContentStream contentStream = - new PDPageContentStream( - subDoc, subPage, AppendMode.APPEND, true, true)) { + new PDPageContentStream( + subDoc, subPage, AppendMode.APPEND, true, true)) { // Set clipping area and position float translateX = -subPageWidth * i; diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java index 829dd5371..c22135bbc 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/SplitPdfBySectionsRequest.java @@ -12,20 +12,20 @@ import stirling.software.common.model.api.PDFFile; @EqualsAndHashCode(callSuper = true) public class SplitPdfBySectionsRequest extends PDFFile { @Schema( - description = "Pages to be split by section", - defaultValue = "all", - requiredMode = Schema.RequiredMode.REQUIRED) + description = "Pages to be split by section", + defaultValue = "all", + requiredMode = Schema.RequiredMode.REQUIRED) private String pageNumbers; @Schema( - implementation = SplitTypes.class, - description = - "Modes for page split. Valid values are:\n" - + "SPLIT_ALL_EXCEPT_FIRST_AND_LAST: Splits all except the first and the last pages.\n" - + "SPLIT_ALL_EXCEPT_FIRST: Splits all except the first page.\n" - + "SPLIT_ALL_EXCEPT_LAST: Splits all except the last page.\n" - + "SPLIT_ALL: Splits all pages.\n" - + "CUSTOM: Custom split.\n") + implementation = SplitTypes.class, + description = + "Modes for page split. Valid values are:\n" + + "SPLIT_ALL_EXCEPT_FIRST_AND_LAST: Splits all except the first and the last pages.\n" + + "SPLIT_ALL_EXCEPT_FIRST: Splits all except the first page.\n" + + "SPLIT_ALL_EXCEPT_LAST: Splits all except the last page.\n" + + "SPLIT_ALL: Splits all pages.\n" + + "CUSTOM: Custom split.\n") private String splitMode; @Schema( From b97a9c727ae40b888cdf84a759c4187431274866 Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Mon, 4 Aug 2025 17:21:46 +0100 Subject: [PATCH 6/9] Hide 'pages to split' section when not in custom mode --- .../api/SplitPdfBySectionsController.java | 9 +++++---- .../main/resources/messages_en_GB.properties | 2 +- .../static/css/split-pdf-by-sections.css | 3 +++ .../templates/split-pdf-by-sections.html | 18 ++++++++++++------ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java index 08f1dfeb7..f787831e9 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java @@ -58,10 +58,11 @@ public class SplitPdfBySectionsController { MultipartFile file = request.getFileInput(); String pageNumbers = request.getPageNumbers(); - SplitTypes splitMode = Optional.ofNullable(request.getSplitMode()) - .map(SplitTypes::valueOf) - .orElse(SplitTypes.SPLIT_ALL); - + SplitTypes splitMode = + Optional.ofNullable(request.getSplitMode()) + .map(SplitTypes::valueOf) + .orElse(SplitTypes.SPLIT_ALL); + PDDocument sourceDocument = pdfDocumentFactory.load(file); Set pagesToSplit = diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index e3579ef48..af727ea48 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -1588,7 +1588,7 @@ split-by-sections.submit=Split PDF split-by-sections.merge=Merge Into One PDF split-by-sections.pageToSplit=Pages to split (Enter a comma-separated list of page numbers) : split-by-sections.pageToSplit.placeholder=(e.g. 1,2,6) -split-by-sections.mode=Mode +split-by-sections.mode=Split Mode split-by-sections.mode.1=Split all except first and last split-by-sections.mode.2=Split all except first split-by-sections.mode.3=Split all except last diff --git a/app/core/src/main/resources/static/css/split-pdf-by-sections.css b/app/core/src/main/resources/static/css/split-pdf-by-sections.css index 7520c10e5..b949000af 100644 --- a/app/core/src/main/resources/static/css/split-pdf-by-sections.css +++ b/app/core/src/main/resources/static/css/split-pdf-by-sections.css @@ -8,3 +8,6 @@ position: absolute; background-color: red; /* Line color */ } +#pageToSplitSection { + display: none; +} diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index 8c0e2bb62..3ea76bf57 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -21,7 +21,7 @@
- +
-
+
+ th:placeholder="#{split-by-sections.pageToSplit.placeholder}">
@@ -95,11 +95,17 @@ this.value = this.value.replace(/\s+/g, '');; }); - // Only enable the page list input field when split mode is custom. + // Only display the page input field when split mode is custom. function togglePageInput() { const mode = document.getElementById('splitMode').value; - const pageListInput = document.getElementById('pageToSplit'); - pageListInput.disabled = mode !== "CUSTOM"; + const pageInputSection = document.getElementById('pageToSplitSection'); + if (mode === "CUSTOM") { + pageInputSection.style.display = "block"; + document.getElementById('pageToSplit').setAttribute("required", "true"); + } else { + pageInputSection.style.display = "none"; + document.getElementById('pageToSplit').removeAttribute("required", "true"); + } } document.getElementById('splitMode').addEventListener('change', togglePageInput); From cf3ef248ca44f5340f70a3bbc8bb69da46ca227a Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Fri, 8 Aug 2025 14:39:41 +0100 Subject: [PATCH 7/9] =?UTF-8?q?Update=20default=20split=20mode=20to=20?= =?UTF-8?q?=E2=80=9CSplit=20All=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/src/main/resources/messages_en_GB.properties | 10 +++++----- .../resources/templates/split-pdf-by-sections.html | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index af727ea48..536cb1f03 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -1589,11 +1589,11 @@ split-by-sections.merge=Merge Into One PDF split-by-sections.pageToSplit=Pages to split (Enter a comma-separated list of page numbers) : split-by-sections.pageToSplit.placeholder=(e.g. 1,2,6) split-by-sections.mode=Split Mode -split-by-sections.mode.1=Split all except first and last -split-by-sections.mode.2=Split all except first -split-by-sections.mode.3=Split all except last -split-by-sections.mode.4=Split all -split-by-sections.mode.5=Custom. Specify pages to split +split-by-sections.mode.1=Split All Except First & Last +split-by-sections.mode.2=Split All Except First +split-by-sections.mode.3=Split All Except Last +split-by-sections.mode.4=Split All Pages +split-by-sections.mode.5=Custom: Specify Pages diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index 3ea76bf57..42576df29 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -23,10 +23,10 @@
From 7c055ce55b64a2f7351fda6a7aff4b1f6ea9649b Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Fri, 8 Aug 2025 15:30:23 +0100 Subject: [PATCH 8/9] Fix syntax: removed 'required' from th:placeholder attribute. --- .../src/main/resources/templates/split-pdf-by-sections.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/src/main/resources/templates/split-pdf-by-sections.html b/app/core/src/main/resources/templates/split-pdf-by-sections.html index 42576df29..e795738a3 100644 --- a/app/core/src/main/resources/templates/split-pdf-by-sections.html +++ b/app/core/src/main/resources/templates/split-pdf-by-sections.html @@ -104,7 +104,7 @@ document.getElementById('pageToSplit').setAttribute("required", "true"); } else { pageInputSection.style.display = "none"; - document.getElementById('pageToSplit').removeAttribute("required", "true"); + document.getElementById('pageToSplit').removeAttribute("required"); } } From b0a63fcafcaf782044a362ecc03536494234bdf0 Mon Sep 17 00:00:00 2001 From: Ping Lin Date: Fri, 8 Aug 2025 15:35:10 +0100 Subject: [PATCH 9/9] =?UTF-8?q?Hide=20=E2=80=98Custom=20page=20order=20inp?= =?UTF-8?q?ut=E2=80=99=20section=20when=20not=20in=20Custom=20mode=20on=20?= =?UTF-8?q?https://stirlingpdf.io/pdf-organizer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/templates/pdf-organizer.html | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/core/src/main/resources/templates/pdf-organizer.html b/app/core/src/main/resources/templates/pdf-organizer.html index 746a6bafd..8e2937eea 100644 --- a/app/core/src/main/resources/templates/pdf-organizer.html +++ b/app/core/src/main/resources/templates/pdf-organizer.html @@ -42,22 +42,29 @@
-
+
+ th:placeholder="#{pdfOrganiser.placeholder}">