From 0f7ea1aed1ab32748d704613278f29612d9056d3 Mon Sep 17 00:00:00 2001 From: Ludy Date: Thu, 30 Oct 2025 11:09:52 +0100 Subject: [PATCH] feat(signature): add SVG file support for saved signatures (#4742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This update adds full support for SVG signature files within the **Sign module**. Previously, SVG images could be uploaded and used directly but did not appear under the “Saved Signatures” section. ### What was changed - **`SignatureService`**: Extended `isImageFile()` method to include `.svg` file extension, ensuring SVGs are recognized as valid image files. - **`SignatureController`**: Enhanced response handling using `MediaTypeFactory` to dynamically determine and return the correct `MediaType` based on the file name. This allows serving `image/svg+xml` for SVG files instead of the previous hardcoded `image/jpeg`. ### Why the change was made SVG signature files were not appearing in “Saved Signatures” even though they could be uploaded and used manually. This fix ensures consistent handling and display of SVG images alongside other image types (JPG, PNG, GIF). Closes #4731 --- ## 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/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- .../SPDF/controller/web/SignatureController.java | 15 +++++++++++---- .../software/SPDF/service/SignatureService.java | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/web/SignatureController.java b/app/core/src/main/java/stirling/software/SPDF/controller/web/SignatureController.java index de03680e1..65d34c0ef 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/web/SignatureController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/web/SignatureController.java @@ -1,10 +1,12 @@ package stirling.software.SPDF.controller.web; import java.io.IOException; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.MediaTypeFactory; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -41,9 +43,14 @@ public class SignatureController { return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); } byte[] imageBytes = signatureService.getSignatureBytes(username, fileName); - return ResponseEntity.ok() - .contentType( // Adjust based on file type - MediaType.IMAGE_JPEG) - .body(imageBytes); + + Optional mediaType = MediaTypeFactory.getMediaType(fileName); + if (mediaType.isPresent() && mediaType.get().toString().startsWith("image/")) { + return ResponseEntity.ok() + .contentType( // Adjust based on file type + mediaType.get()) + .body(imageBytes); + } + return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); } } diff --git a/app/core/src/main/java/stirling/software/SPDF/service/SignatureService.java b/app/core/src/main/java/stirling/software/SPDF/service/SignatureService.java index fd27439ed..362e50834 100644 --- a/app/core/src/main/java/stirling/software/SPDF/service/SignatureService.java +++ b/app/core/src/main/java/stirling/software/SPDF/service/SignatureService.java @@ -96,7 +96,8 @@ public class SignatureService { return fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".png") - || fileName.endsWith(".gif"); + || fileName.endsWith(".gif") + || fileName.endsWith(".svg"); } private void validateFileName(String fileName) {