Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chottuthejimmy committed Sep 24, 2024
2 parents 678406f + 9b96367 commit 06afe73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ public ResponseEntity<byte[]> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +20,8 @@
@Component
public class CustomPDDocumentFactory {

private static final Logger logger = LoggerFactory.getLogger(CustomPDDocumentFactory.class);

private final PdfMetadataService pdfMetadataService;

@Autowired
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
}

0 comments on commit 06afe73

Please sign in to comment.