From da7f0561cba7526dc060570fd673bdbeacf60b6f Mon Sep 17 00:00:00 2001 From: Dardan Date: Tue, 5 Sep 2023 19:48:16 +0200 Subject: [PATCH 1/2] Add side stitch booklet rearrangement --- .../api/RearrangePagesPDFController.java | 16 +++++++++++++++- src/main/resources/templates/pdf-organizer.html | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java index d9cb2686..74e969ec 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java @@ -52,7 +52,7 @@ public class RearrangePagesPDFController { } private enum CustomMode { - REVERSE_ORDER, DUPLEX_SORT, BOOKLET_SORT, ODD_EVEN_SPLIT, REMOVE_FIRST, REMOVE_LAST, REMOVE_FIRST_AND_LAST, + REVERSE_ORDER, DUPLEX_SORT, BOOKLET_SORT, SIDE_STITCH_BOOKLET_SORT, ODD_EVEN_SPLIT, REMOVE_FIRST, REMOVE_LAST, REMOVE_FIRST_AND_LAST, } private List removeFirst(int totalPages) { @@ -114,6 +114,18 @@ public class RearrangePagesPDFController { return newPageOrder; } + private List sideStitchBooklet(int totalPages) { + List newPageOrder = new ArrayList<>(); + for (int i = 0; i < (totalPages + 3) / 4; i++) { + int begin = i * 4; + newPageOrder.add(Math.min(begin + 3, totalPages - 1)); + newPageOrder.add(Math.min(begin, totalPages - 1)); + newPageOrder.add(Math.min(begin + 1, totalPages - 1)); + newPageOrder.add(Math.min(begin + 2, totalPages - 1)); + } + return newPageOrder; + } + private List oddEvenSplit(int totalPages) { List newPageOrder = new ArrayList<>(); for (int i = 1; i <= totalPages; i += 2) { @@ -135,6 +147,8 @@ public class RearrangePagesPDFController { return duplexSort(totalPages); case BOOKLET_SORT: return bookletSort(totalPages); + case SIDE_STITCH_BOOKLET_SORT: + return sideStitchBooklet(totalPages); case ODD_EVEN_SPLIT: return oddEvenSplit(totalPages); case REMOVE_FIRST: diff --git a/src/main/resources/templates/pdf-organizer.html b/src/main/resources/templates/pdf-organizer.html index 96944649..c6e1508f 100644 --- a/src/main/resources/templates/pdf-organizer.html +++ b/src/main/resources/templates/pdf-organizer.html @@ -23,6 +23,7 @@ + @@ -53,4 +54,4 @@
- \ No newline at end of file + From d039c8e62e9493af71fa2bc7cb33b2f4658626de Mon Sep 17 00:00:00 2001 From: Dardan Date: Tue, 5 Sep 2023 20:05:33 +0200 Subject: [PATCH 2/2] Use tabs instead of spaces --- .../api/RearrangePagesPDFController.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java index 74e969ec..78df1f41 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java @@ -114,16 +114,16 @@ public class RearrangePagesPDFController { return newPageOrder; } - private List sideStitchBooklet(int totalPages) { - List newPageOrder = new ArrayList<>(); - for (int i = 0; i < (totalPages + 3) / 4; i++) { - int begin = i * 4; - newPageOrder.add(Math.min(begin + 3, totalPages - 1)); - newPageOrder.add(Math.min(begin, totalPages - 1)); - newPageOrder.add(Math.min(begin + 1, totalPages - 1)); - newPageOrder.add(Math.min(begin + 2, totalPages - 1)); - } - return newPageOrder; + private List sideStitchBooklet(int totalPages) { + List newPageOrder = new ArrayList<>(); + for (int i = 0; i < (totalPages + 3) / 4; i++) { + int begin = i * 4; + newPageOrder.add(Math.min(begin + 3, totalPages - 1)); + newPageOrder.add(Math.min(begin, totalPages - 1)); + newPageOrder.add(Math.min(begin + 1, totalPages - 1)); + newPageOrder.add(Math.min(begin + 2, totalPages - 1)); + } + return newPageOrder; } private List oddEvenSplit(int totalPages) { @@ -147,8 +147,8 @@ public class RearrangePagesPDFController { return duplexSort(totalPages); case BOOKLET_SORT: return bookletSort(totalPages); - case SIDE_STITCH_BOOKLET_SORT: - return sideStitchBooklet(totalPages); + case SIDE_STITCH_BOOKLET_SORT: + return sideStitchBooklet(totalPages); case ODD_EVEN_SPLIT: return oddEvenSplit(totalPages); case REMOVE_FIRST: