From c650a766a961ad3d68d092f359729d3741f1a30c Mon Sep 17 00:00:00 2001 From: creator1999 <38176970+creator1999@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:24:38 +0530 Subject: [PATCH] Added functionality to set font size and font type in both frontend and backend. (#1783) * Added variables * Added functionality to add font size and font type in both frontend and backend * new changes suggested has been added --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> --- .../software/SPDF/SPdfApplication.java | 1 + .../SPDF/config/security/UserService.java | 9 +- .../api/misc/PageNumbersController.java | 21 +- .../controller/web/AccountWebController.java | 23 +- .../stirling/software/SPDF/model/User.java | 4 +- .../model/api/misc/AddPageNumbersRequest.java | 3 + .../SPDF/repository/UserRepository.java | 5 +- .../software/SPDF/utils/GeneralUtils.java | 1 - src/main/resources/messages_en_GB.properties | 3 +- src/main/resources/messages_en_US.properties | 3 +- .../templates/misc/add-page-numbers.html | 267 +++++++++--------- 11 files changed, 189 insertions(+), 151 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 6c90ee3c..bc17e0f1 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -31,6 +31,7 @@ public class SPdfApplication { @Autowired private Environment env; + @Autowired ApplicationProperties applicationProperties; private static String serverPortStatic; diff --git a/src/main/java/stirling/software/SPDF/config/security/UserService.java b/src/main/java/stirling/software/SPDF/config/security/UserService.java index 78f17822..5adfdbc7 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserService.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserService.java @@ -1,5 +1,9 @@ package stirling.software.SPDF.config.security; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -13,6 +17,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Service; + import stirling.software.SPDF.config.DatabaseBackupInterface; import stirling.software.SPDF.config.security.session.SessionPersistentRegistry; import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface; @@ -23,10 +28,6 @@ import stirling.software.SPDF.model.User; import stirling.software.SPDF.repository.AuthorityRepository; import stirling.software.SPDF.repository.UserRepository; -import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; - @Service public class UserService implements UserServiceInterface { diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java index 337a9f48..ba31dc83 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java @@ -43,6 +43,7 @@ public class PageNumbersController { "This operation takes an input PDF file and adds page numbers to it. Input:PDF Output:PDF Type:SISO") public ResponseEntity addPageNumbers(@ModelAttribute AddPageNumbersRequest request) throws IOException { + MultipartFile file = request.getFileInput(); String customMargin = request.getCustomMargin(); int position = request.getPosition(); @@ -52,7 +53,8 @@ public class PageNumbersController { int pageNumber = startingNumber; byte[] fileBytes = file.getBytes(); PDDocument document = Loader.loadPDF(fileBytes); - + float font_size = request.getFontSize(); + String font_type = request.getFontType(); float marginFactor; switch (customMargin.toLowerCase()) { case "small": @@ -73,7 +75,7 @@ public class PageNumbersController { break; } - float fontSize = 12.0f; + float fontSize = font_size; if (pagesToNumber == null || pagesToNumber.length() == 0) { pagesToNumber = "all"; } @@ -131,7 +133,20 @@ public class PageNumbersController { new PDPageContentStream( document, page, PDPageContentStream.AppendMode.APPEND, true, true); contentStream.beginText(); - contentStream.setFont(new PDType1Font(Standard14Fonts.FontName.HELVETICA), fontSize); + switch (font_type.toLowerCase()) { + case "helvetica": + contentStream.setFont( + new PDType1Font(Standard14Fonts.FontName.HELVETICA), fontSize); + break; + case "courier": + contentStream.setFont( + new PDType1Font(Standard14Fonts.FontName.COURIER), fontSize); + break; + case "times": + contentStream.setFont( + new PDType1Font(Standard14Fonts.FontName.TIMES_ROMAN), fontSize); + break; + } contentStream.newLineAtOffset(x, y); contentStream.showText(text); contentStream.endText(); diff --git a/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java b/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java index 739f2600..2f6b5042 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java @@ -1,10 +1,10 @@ package stirling.software.SPDF.controller.web; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; -import lombok.extern.slf4j.Slf4j; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.Authentication; @@ -13,6 +13,14 @@ import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.swagger.v3.oas.annotations.tags.Tag; + +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; import stirling.software.SPDF.config.security.session.SessionPersistentRegistry; import stirling.software.SPDF.model.*; import stirling.software.SPDF.model.ApplicationProperties.Security.OAUTH2; @@ -22,11 +30,6 @@ import stirling.software.SPDF.model.provider.GoogleProvider; import stirling.software.SPDF.model.provider.KeycloakProvider; import stirling.software.SPDF.repository.UserRepository; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; - @Controller @Slf4j @Tag(name = "Account Security", description = "Account Security APIs") diff --git a/src/main/java/stirling/software/SPDF/model/User.java b/src/main/java/stirling/software/SPDF/model/User.java index 7006712b..ddfb7135 100644 --- a/src/main/java/stirling/software/SPDF/model/User.java +++ b/src/main/java/stirling/software/SPDF/model/User.java @@ -1,7 +1,5 @@ package stirling.software.SPDF.model; -import jakarta.persistence.*; - import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; @@ -9,6 +7,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import jakarta.persistence.*; + @Entity @Table(name = "users") public class User implements Serializable { diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java index 5622903a..9f3b5266 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java @@ -15,6 +15,9 @@ public class AddPageNumbersRequest extends PDFWithPageNums { allowableValues = {"small", "medium", "large"}) private String customMargin; + private float fontSize; + private String fontType; + @Schema(description = "Position: 1 of 9 positions", minimum = "1", maximum = "9") private int position; diff --git a/src/main/java/stirling/software/SPDF/repository/UserRepository.java b/src/main/java/stirling/software/SPDF/repository/UserRepository.java index a80b58cb..3da21634 100644 --- a/src/main/java/stirling/software/SPDF/repository/UserRepository.java +++ b/src/main/java/stirling/software/SPDF/repository/UserRepository.java @@ -1,11 +1,12 @@ package stirling.software.SPDF.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import stirling.software.SPDF.model.User; -import java.util.Optional; +import stirling.software.SPDF.model.User; @Repository public interface UserRepository extends JpaRepository { diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index 480badcb..21d921c8 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -262,5 +262,4 @@ public class GeneralUtils { } return true; } - } diff --git a/src/main/resources/messages_en_GB.properties b/src/main/resources/messages_en_GB.properties index 625523b9..a06d4f61 100644 --- a/src/main/resources/messages_en_GB.properties +++ b/src/main/resources/messages_en_GB.properties @@ -3,7 +3,8 @@ ########### # the direction that the language is written (ltr = left to right, rtl = right to left) language.direction=ltr - +addPageNumbers.fontSize=Font Size +addPageNumbers.fontName=Font Name pdfPrompt=Select PDF(s) multiPdfPrompt=Select PDFs (2+) multiPdfDropPrompt=Select (or drag & drop) all PDFs you require diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index 2a180435..328a8c32 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -3,7 +3,8 @@ ########### # the direction that the language is written (ltr=left to right, rtl = right to left) language.direction=ltr - +addPageNumbers.fontSize=Font Size +addPageNumbers.fontName=Font Name pdfPrompt=Select PDF(s) multiPdfPrompt=Select PDFs (2+) multiPdfDropPrompt=Select (or drag & drop) all PDFs you require diff --git a/src/main/resources/templates/misc/add-page-numbers.html b/src/main/resources/templates/misc/add-page-numbers.html index bb51fae6..eb9a87de 100644 --- a/src/main/resources/templates/misc/add-page-numbers.html +++ b/src/main/resources/templates/misc/add-page-numbers.html @@ -1,140 +1,153 @@ - + - - + .selectedPosition.selectedHovered { + background-color: #006600; + } + + - - -
-
- -

-
-
-
-
- 123 - -
-
-
-
-
- - -
-
- -
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
-
- -
- - -
-
- - -
-
- - -
- -
-
+ + +
+
+ +

+
+
+
+
+ 123 +
+
+
+
+
+ + +
+
+ +
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
-
-
- - \ No newline at end of file + +
+ +
+ +