From 58423bfc21c3c5be6ddda90ca550b249826f42b3 Mon Sep 17 00:00:00 2001 From: Saud Fatayerji Date: Sun, 5 Feb 2023 02:45:33 +0300 Subject: [PATCH 1/4] Redesigned the rotate page --- .../resources/templates/fragments/common.html | 24 +++++ src/main/resources/templates/rotate-pdf.html | 102 ++++++++++++++---- 2 files changed, 108 insertions(+), 18 deletions(-) diff --git a/src/main/resources/templates/fragments/common.html b/src/main/resources/templates/fragments/common.html index d8abe242..18352416 100644 --- a/src/main/resources/templates/fragments/common.html +++ b/src/main/resources/templates/fragments/common.html @@ -6,6 +6,9 @@ + + + + + + +
+
+ + +
+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/rotate-pdf.html b/src/main/resources/templates/rotate-pdf.html index cd17e8aa..d22c40c8 100644 --- a/src/main/resources/templates/rotate-pdf.html +++ b/src/main/resources/templates/rotate-pdf.html @@ -15,28 +15,20 @@

Rotate PDF

+
+
+ - - -
- +
+
-
- +
+ + + +
-
@@ -44,6 +36,80 @@
+ + + \ No newline at end of file From f093d657296cedb7df8119a84276bfe989e0afb7 Mon Sep 17 00:00:00 2001 From: Saud Fatayerji Date: Sun, 5 Feb 2023 18:08:43 +0300 Subject: [PATCH 2/4] Fixed bugs --- .../SPDF/controller/RotationController.java | 4 +- src/main/resources/templates/rotate-pdf.html | 38 ++++++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/RotationController.java b/src/main/java/stirling/software/SPDF/controller/RotationController.java index 42676f6d..436dc484 100644 --- a/src/main/java/stirling/software/SPDF/controller/RotationController.java +++ b/src/main/java/stirling/software/SPDF/controller/RotationController.java @@ -37,7 +37,7 @@ public class RotationController { @PostMapping("/rotate-pdf") public ResponseEntity rotatePDF(@RequestParam("fileInput") MultipartFile pdfFile, - @RequestParam("angle") String angle) throws IOException { + @RequestParam("angle") Integer angle) throws IOException { // Load the PDF document PDDocument document = PDDocument.load(pdfFile.getBytes()); @@ -50,7 +50,7 @@ public class RotationController { while (iterPage.hasNext()) { PDPage page = iterPage.next(); - page.setRotation(Integer.valueOf(angle)); + page.setRotation(page.getRotation() + angle); } return PdfUtils.pdfDocToWebResponse(document, pdfFile.getName() + "_rotated.pdf"); diff --git a/src/main/resources/templates/rotate-pdf.html b/src/main/resources/templates/rotate-pdf.html index d22c40c8..58855922 100644 --- a/src/main/resources/templates/rotate-pdf.html +++ b/src/main/resources/templates/rotate-pdf.html @@ -24,9 +24,19 @@
- + - +
@@ -57,8 +67,13 @@ const canvas = document.createElement("canvas"); // set the canvas size to the size of the page - canvas.width = page.view[2]; - canvas.height = page.view[3]; + if (page.rotate == 90 || page.rotate == 270) { + canvas.width = page.view[3]; + canvas.height = page.view[2]; + } else { + canvas.width = page.view[2]; + canvas.height = page.view[3]; + } // render the page onto the canvas var renderContext = { @@ -71,14 +86,14 @@ }); function rotate(deg) { - var lastTransform = preview.style.transform; + var lastTransform = preview.style.rotate; if (!lastTransform) { lastTransform = "0"; } const lastAngle = parseInt(lastTransform.replace(/[^\d-]/g, '')); const newAngle = lastAngle + deg; - preview.style.transform = "rotate(" + newAngle + "deg)"; + preview.style.rotate = newAngle + "deg"; angleInput.value = newAngle; } @@ -86,10 +101,14 @@ #pdf-preview { margin: 0 auto; display: block; - max-width: 100%; - max-height: 100%; + max-width: calc(100% - 30px); + max-height: calc(100% - 30px); box-shadow: 0 0 4px rgba(100,100,100,.25); - transition: transform .3s; + transition: rotate .3s; + position: absolute; + top: 50%; + left: 50%; + translate: -50% -50%; } .previewContainer { aspect-ratio: 1; @@ -100,6 +119,7 @@ padding: 15px; display: none; overflow: hidden; + position: relative; } .buttonContainer { From 38925ea4cab2efa00b178035254749a6bafea691 Mon Sep 17 00:00:00 2001 From: Saud Fatayerji Date: Sun, 5 Feb 2023 22:04:37 +0300 Subject: [PATCH 3/4] Fixed merge conflict. Cleaned up code --- .../resources/templates/fragments/common.html | 4 +- src/main/resources/templates/rotate-pdf.html | 58 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/main/resources/templates/fragments/common.html b/src/main/resources/templates/fragments/common.html index 18352416..4340d5e8 100644 --- a/src/main/resources/templates/fragments/common.html +++ b/src/main/resources/templates/fragments/common.html @@ -102,7 +102,7 @@
- +
@@ -113,7 +113,7 @@ if (fileNames) { $(this).siblings(".custom-file-label").addClass("selected").html(fileNames); } else { - $(this).siblings(".custom-file-label").addClass("selected").html("Choose file"); + $(this).siblings(".custom-file-label").addClass("selected").html([[#{pdfPrompt}]]); } }); diff --git a/src/main/resources/templates/rotate-pdf.html b/src/main/resources/templates/rotate-pdf.html index 2ce89690..68418b69 100644 --- a/src/main/resources/templates/rotate-pdf.html +++ b/src/main/resources/templates/rotate-pdf.html @@ -19,24 +19,26 @@
-
- -
+