From 1c6e5df77d10fcd6f77c7b129041931fb1ac2428 Mon Sep 17 00:00:00 2001 From: maxi322 <66129899+maxi322@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:52:57 +0200 Subject: [PATCH 1/3] [fix]: check for encryption in PageNumbers (#1949) [fix]: check for empty password encryption on load Co-authored-by: maxi322 --- .../api/SplitPdfByChaptersController.java | 9 --------- .../SPDF/service/CustomPDDocumentFactory.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/SplitPdfByChaptersController.java b/src/main/java/stirling/software/SPDF/controller/api/SplitPdfByChaptersController.java index 9d03f8b6b0..0cca8f7886 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/SplitPdfByChaptersController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/SplitPdfByChaptersController.java @@ -67,15 +67,6 @@ public ResponseEntity splitPdf(@ModelAttribute SplitPdfByChaptersRequest } PDDocument sourceDocument = Loader.loadPDF(file.getBytes()); - // checks if the document is encrypted by an empty user password - if (sourceDocument.isEncrypted()) { - try { - sourceDocument.setAllSecurityToBeRemoved(true); - logger.info("Removing security from the source document "); - } catch (Exception e) { - logger.warn("Cannot decrypt the pdf"); - } - } PDDocumentOutline outline = sourceDocument.getDocumentCatalog().getDocumentOutline(); if (outline == null) { diff --git a/src/main/java/stirling/software/SPDF/service/CustomPDDocumentFactory.java b/src/main/java/stirling/software/SPDF/service/CustomPDDocumentFactory.java index b3f9eec7e3..2d3d8990e0 100644 --- a/src/main/java/stirling/software/SPDF/service/CustomPDDocumentFactory.java +++ b/src/main/java/stirling/software/SPDF/service/CustomPDDocumentFactory.java @@ -7,6 +7,8 @@ import org.apache.pdfbox.Loader; import org.apache.pdfbox.pdmodel.PDDocument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -18,6 +20,8 @@ @Component public class CustomPDDocumentFactory { + private static final Logger logger = LoggerFactory.getLogger(CustomPDDocumentFactory.class); + private final PdfMetadataService pdfMetadataService; @Autowired @@ -71,6 +75,7 @@ public PDDocument load(InputStream input) throws IOException { public PDDocument load(byte[] input) throws IOException { PDDocument document = Loader.loadPDF(input); pdfMetadataService.setDefaultMetadata(document); + removezeropassword(document); return document; } @@ -96,5 +101,17 @@ private PDDocument load(byte[] bytes, String password) throws IOException { return document; } + private PDDocument removezeropassword(PDDocument document) throws IOException { + if (document.isEncrypted()) { + try { + logger.info("Removing security from the source document"); + document.setAllSecurityToBeRemoved(true); + } catch (Exception e) { + logger.warn("Cannot decrypt the pdf"); + } + } + return document; + } + // Add other load methods as needed, following the same pattern } From 3ded6de5769b3f66ff0168a446b734865ae7f6f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:27:37 +0100 Subject: [PATCH 2/3] Bump springBootVersion from 3.3.3 to 3.3.4 (#1953) Bumps `springBootVersion` from 3.3.3 to 3.3.4. Updates `org.springframework.boot:spring-boot-starter-web` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-jetty` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-thymeleaf` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-security` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-data-jpa` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-oauth2-client` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-test` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-starter-actuator` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) Updates `org.springframework.boot:spring-boot-devtools` from 3.3.3 to 3.3.4 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.3.3...v3.3.4) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-web dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-jetty dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-thymeleaf dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-security dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-data-jpa dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-oauth2-client dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-test dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-starter-actuator dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-devtools dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ce09352a6e..870a6ad4a5 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ plugins { import com.github.jk1.license.render.* ext { - springBootVersion = "3.3.3" + springBootVersion = "3.3.4" pdfboxVersion = "3.0.3" logbackVersion = "1.5.7" imageioVersion = "3.11.0" From 9b9636749679a81880ecb4e12055cd629d55132d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:27:46 +0100 Subject: [PATCH 3/3] Bump commons-io:commons-io from 2.16.1 to 2.17.0 (#1955) Bumps commons-io:commons-io from 2.16.1 to 2.17.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 870a6ad4a5..05f9d9c333 100644 --- a/build.gradle +++ b/build.gradle @@ -162,7 +162,7 @@ dependencies { runtimeOnly "com.twelvemonkeys.imageio:imageio-webp:$imageioVersion" // runtimeOnly "com.twelvemonkeys.imageio:imageio-xwd:$imageioVersion" - implementation "commons-io:commons-io:2.16.1" + implementation "commons-io:commons-io:2.17.0" implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0" //general PDF