From 632f29d1d6723c46ccdac54eb9bf5fc428e5d429 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Mon, 8 May 2023 12:36:48 +0100 Subject: [PATCH] ./ --- .../api/other/BlankPageController.java | 19 +++++++------------ .../other/ExtractImageScansController.java | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java b/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java index 40b6bdb1..d84ea78c 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import stirling.software.SPDF.utils.ImageFinder; +import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.ProcessExecutor; import java.awt.image.BufferedImage; @@ -45,13 +46,13 @@ public class BlankPageController { boolean hasText = !pageText.trim().isEmpty(); if (hasText) { pagesToKeepIndex.add(pageIndex); - System.out.print("page " + pageIndex + " has text"); + System.out.println("page " + pageIndex + " has text"); continue; } boolean hasImages = hasImagesOnPage(page); if (hasImages) { pagesToKeepIndex.add(pageIndex); - System.out.print("page " + pageIndex + " has image"); + System.out.println("page " + pageIndex + " has image"); continue; } } @@ -66,7 +67,7 @@ public class BlankPageController { BufferedImage image = pdfRenderer.renderImageWithDPI(i - 1, 300); ImageIO.write(image, "png", tempFile.toFile()); - List command = new ArrayList<>(Arrays.asList("python3", "/scripts/detect-blank-pages.py", tempFile.toString())); + List command = new ArrayList<>(Arrays.asList("python3", "./scripts/detect-blank-pages.py", tempFile.toString())); // Run CLI command int returnCode = ProcessExecutor.getInstance(ProcessExecutor.Processes.PYTHON_OPENCV).runCommandWithOutputHandling(command); @@ -78,13 +79,11 @@ public class BlankPageController { System.out.print("Found blank page skipping, page #" + i); } } + - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - outputDocument.save(outputStream); - outputDocument.close(); document.close(); - - return new ResponseEntity<>(outputStream.toByteArray(), HttpStatus.OK); + + return PdfUtils.pdfDocToWebResponse(outputDocument, inputFile.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_blanksRemoved.pdf"); } catch (IOException e) { e.printStackTrace(); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); @@ -96,8 +95,4 @@ public class BlankPageController { imageFinder.processPage(page); return imageFinder.hasImages(); } - - - - // ... rest of the code (ImageFinder class and hasImagesOnPage method) } diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java b/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java index 987970ba..bb15eee9 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java @@ -82,7 +82,7 @@ public class ExtractImageScansController { for (int i = 0; i < images.size(); i++) { Path tempDir = Files.createTempDirectory("openCV_output"); - List command = new ArrayList<>(Arrays.asList("python3", "/scripts/split_photos.py", images.get(i), tempDir.toString(), String.valueOf(angleThreshold), + List command = new ArrayList<>(Arrays.asList("python3", "./scripts/split_photos.py", images.get(i), tempDir.toString(), String.valueOf(angleThreshold), String.valueOf(tolerance), String.valueOf(minArea), String.valueOf(minContourArea), String.valueOf(borderSize))); // Run CLI command