From 30444fc9bbbe478054ee495db4dc3084e8a18964 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Fri, 26 Apr 2024 23:27:40 +0100 Subject: [PATCH] commit (#1128) * commit * formatting --- README.md | 2 +- .../api/misc/FakeScanControllerWIP.java | 47 ++++++++++++++----- .../api/misc/PrintFileController.java | 11 ++--- .../software/SPDF/utils/PdfUtils.java | 2 - .../resources/templates/fragments/navbar.html | 8 ++-- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 70c87568446..3e22e201099 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ Stirling PDF allows easy customization of the app. Includes things like - Custom application name -- Custom slogans, icons, images, and even custom HTML (via file overrides) +- Custom slogans, icons, images css etc (via file overrides) (Does not currently support html) There are two options for this, either using the generated settings file ``settings.yml`` This file is located in the ``/configs`` directory and follows standard YAML formatting diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java index 834c8711c64..2400c0d31d6 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java @@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile; import io.github.pixee.security.Filenames; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -51,7 +52,9 @@ public class FakeScanControllerWIP { private static final Logger logger = LoggerFactory.getLogger(FakeScanControllerWIP.class); + // TODO finish @PostMapping(consumes = "multipart/form-data", value = "/fake-scan") + @Hidden @Operation( summary = "Repair a PDF file", description = @@ -94,14 +97,13 @@ public ResponseEntity fakeScan(@ModelAttribute PDFFile request) throws I public BufferedImage processImage(BufferedImage image) { // Rotation - addDustAndHairs(image, 50); - // image = rotate(image, 1); + image = softenEdges(image, 50); + image = rotate(image, 1); - // image = softenEdges(image, 5); image = applyGaussianBlur(image, 0.5); - addGaussianNoise(image, 0.8); + addGaussianNoise(image, 0.5); image = linearStretch(image); - + addDustAndHairs(image, 3); return image; } @@ -156,32 +158,51 @@ public BufferedImage softenEdges(BufferedImage image, int featherRadius) { g2.drawImage(image, 0, 0, null); g2.setComposite(AlphaComposite.DstIn); + + // Top edge g2.setPaint( new GradientPaint( - 0, 0, new Color(0, 0, 0, 1f), 0, featherRadius, new Color(0, 0, 0, 0f))); - g2.fillRect(0, 0, width, featherRadius); // top edge + 0, + 0, + new Color(0, 0, 0, 1f), + 0, + featherRadius * 2, + new Color(0, 0, 0, 0f))); + g2.fillRect(0, 0, width, featherRadius); + + // Bottom edge g2.setPaint( new GradientPaint( 0, - height - featherRadius, + height - featherRadius * 2, new Color(0, 0, 0, 0f), 0, height, new Color(0, 0, 0, 1f))); - g2.fillRect(0, height - featherRadius, width, featherRadius); // bottom edge + g2.fillRect(0, height - featherRadius, width, featherRadius); + + // Left edge g2.setPaint( new GradientPaint( - 0, 0, new Color(0, 0, 0, 1f), featherRadius, 0, new Color(0, 0, 0, 0f))); - g2.fillRect(0, 0, featherRadius, height); // left edge + 0, + 0, + new Color(0, 0, 0, 1f), + featherRadius * 2, + 0, + new Color(0, 0, 0, 0f))); + g2.fillRect(0, 0, featherRadius, height); + + // Right edge g2.setPaint( new GradientPaint( - width - featherRadius, + width - featherRadius * 2, 0, new Color(0, 0, 0, 0f), width, 0, new Color(0, 0, 0, 1f))); - g2.fillRect(width - featherRadius, 0, featherRadius, height); // right edge + g2.fillRect(width - featherRadius, 0, featherRadius, height); + g2.dispose(); return output; diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/PrintFileController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/PrintFileController.java index 66da699e2e7..bc0a6715f82 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/PrintFileController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/PrintFileController.java @@ -20,12 +20,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import stirling.software.SPDF.model.api.misc.PrintFileRequest; @@ -35,12 +33,13 @@ @Tag(name = "Misc", description = "Miscellaneous APIs") public class PrintFileController { - //TODO - //@PostMapping(value = "/print-file", consumes = "multipart/form-data") - //@Operation( + // TODO + // @PostMapping(value = "/print-file", consumes = "multipart/form-data") + // @Operation( // summary = "Prints PDF/Image file to a set printer", // description = - // "Input of PDF or Image along with a printer name/URL/IP to match against to send it to (Fire and forget) Input:Any Output:N/A Type:SISO") + // "Input of PDF or Image along with a printer name/URL/IP to match against to + // send it to (Fire and forget) Input:Any Output:N/A Type:SISO") public ResponseEntity printFile(@ModelAttribute PrintFileRequest request) throws IOException { MultipartFile file = request.getFileInput(); diff --git a/src/main/java/stirling/software/SPDF/utils/PdfUtils.java b/src/main/java/stirling/software/SPDF/utils/PdfUtils.java index 59a6877e49d..225a2c124d6 100644 --- a/src/main/java/stirling/software/SPDF/utils/PdfUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/PdfUtils.java @@ -342,8 +342,6 @@ public static void addImageToDocument( boolean imageIsLandscape = image.getWidth() > image.getHeight(); PDRectangle pageSize = PDRectangle.A4; - System.out.println(fitOption); - if (autoRotate && imageIsLandscape) { pageSize = new PDRectangle(pageSize.getHeight(), pageSize.getWidth()); } diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html index 306eaed8a4f..8b412a6bb1b 100644 --- a/src/main/resources/templates/fragments/navbar.html +++ b/src/main/resources/templates/fragments/navbar.html @@ -17,20 +17,20 @@