From 872f562aadbb8803e24ef73d2a3920ad6749204e Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 9 Sep 2023 18:21:55 +0100 Subject: [PATCH] misc beginings --- .../api/filters/FilterController.java | 64 +++++++++---------- .../{other => misc}/AutoRenameController.java | 11 ++-- .../AutoSplitPdfController.java | 11 ++-- .../{other => misc}/BlankPageController.java | 18 ++---- .../{other => misc}/CompressController.java | 15 +++-- .../ExtractImageScansController.java | 7 +- .../ExtractImagesController.java | 2 +- .../FakeScanControllerWIP.java | 2 +- .../{other => misc}/MetadataController.java | 2 +- .../api/{other => misc}/OCRController.java | 2 +- .../OverlayImageController.java | 2 +- .../PageNumbersController.java | 2 +- .../api/{other => misc}/RepairController.java | 2 +- .../api/{other => misc}/ShowJavascript.java | 2 +- .../SPDF/model/api/PDFComparison.java | 19 ++++++ .../SPDF/model/api/PDFComparisonAndCount.java | 18 ++++++ .../model/api/filter/ContainsTextRequest.java | 12 ++++ .../model/api/filter/FileSizeRequest.java | 15 +++++ .../model/api/filter/PageRotationRequest.java | 14 ++++ .../model/api/filter/PageSizeRequest.java | 15 +++++ .../model/api/misc/AutoSplitPdfRequest.java | 12 ++++ .../model/api/misc/ExtractHeaderRequest.java | 12 ++++ .../api/misc/ExtractImageScansRequest.java} | 4 +- .../model/api/misc/OptimizePdfRequest.java | 16 +++++ .../api/misc/RemoveBlankPagesRequest.java | 15 +++++ 25 files changed, 221 insertions(+), 73 deletions(-) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/AutoRenameController.java (90%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/AutoSplitPdfController.java (91%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/BlankPageController.java (87%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/CompressController.java (93%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/ExtractImageScansController.java (95%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/ExtractImagesController.java (98%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/FakeScanControllerWIP.java (99%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/MetadataController.java (99%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/OCRController.java (99%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/OverlayImageController.java (98%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/PageNumbersController.java (96%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/RepairController.java (98%) rename src/main/java/stirling/software/SPDF/controller/api/{other => misc}/ShowJavascript.java (97%) create mode 100644 src/main/java/stirling/software/SPDF/model/api/PDFComparison.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/PDFComparisonAndCount.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java rename src/main/java/stirling/software/SPDF/{controller/api/other/MyForm.java => model/api/misc/ExtractImageScansRequest.java} (91%) create mode 100644 src/main/java/stirling/software/SPDF/model/api/misc/OptimizePdfRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/misc/RemoveBlankPagesRequest.java diff --git a/src/main/java/stirling/software/SPDF/controller/api/filters/FilterController.java b/src/main/java/stirling/software/SPDF/controller/api/filters/FilterController.java index bd2e75be..dbb20bfe 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/filters/FilterController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/filters/FilterController.java @@ -6,6 +6,7 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; @@ -15,6 +16,12 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.PDFComparisonAndCount; +import stirling.software.SPDF.model.api.PDFWithPageNums; +import stirling.software.SPDF.model.api.filter.ContainsTextRequest; +import stirling.software.SPDF.model.api.filter.FileSizeRequest; +import stirling.software.SPDF.model.api.filter.PageRotationRequest; +import stirling.software.SPDF.model.api.filter.PageSizeRequest; import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.WebResponseUtils; @@ -24,11 +31,11 @@ public class FilterController { @PostMapping(consumes = "multipart/form-data", value = "/filter-contains-text") @Operation(summary = "Checks if a PDF contains set text, returns true if does", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity containsText( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to be converted to a PDF/A file", required = true) MultipartFile inputFile, - @Parameter(description = "The text to check for", required = true) String text, - @Parameter(description = "The page number to check for text on accepts 'All', ranges like '1-4'", required = false) String pageNumber) - throws IOException, InterruptedException { + public ResponseEntity containsText(@ModelAttribute ContainsTextRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String text = request.getText(); + String pageNumber = request.getPageNumbers(); + PDDocument pdfDocument = PDDocument.load(inputFile.getInputStream()); if (PdfUtils.hasText(pdfDocument, pageNumber, text)) return WebResponseUtils.pdfDocToWebResponse(pdfDocument, inputFile.getOriginalFilename()); @@ -38,10 +45,11 @@ public class FilterController { // TODO @PostMapping(consumes = "multipart/form-data", value = "/filter-contains-image") @Operation(summary = "Checks if a PDF contains an image", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity containsImage( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to be converted to a PDF/A file", required = true) MultipartFile inputFile, - @Parameter(description = "The page number to check for image on accepts 'All', ranges like '1-4'", required = false) String pageNumber) + public ResponseEntity containsImage(@ModelAttribute PDFWithPageNums request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String pageNumber = request.getPageNumbers(); + PDDocument pdfDocument = PDDocument.load(inputFile.getInputStream()); if (PdfUtils.hasImages(pdfDocument, pageNumber)) return WebResponseUtils.pdfDocToWebResponse(pdfDocument, inputFile.getOriginalFilename()); @@ -50,12 +58,10 @@ public class FilterController { @PostMapping(consumes = "multipart/form-data", value = "/filter-page-count") @Operation(summary = "Checks if a PDF is greater, less or equal to a setPageCount", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity pageCount( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file", required = true) MultipartFile inputFile, - @Parameter(description = "Page Count", required = true) String pageCount, - @Parameter(description = "Comparison type", schema = @Schema(description = "The comparison type, accepts Greater, Equal, Less than", allowableValues = { - "Greater", "Equal", "Less" })) String comparator) - throws IOException, InterruptedException { + public ResponseEntity pageCount(@ModelAttribute PDFComparisonAndCount request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String pageCount = request.getPageCount(); + String comparator = request.getComparator(); // Load the PDF PDDocument document = PDDocument.load(inputFile.getInputStream()); int actualPageCount = document.getNumberOfPages(); @@ -83,12 +89,10 @@ public class FilterController { @PostMapping(consumes = "multipart/form-data", value = "/filter-page-size") @Operation(summary = "Checks if a PDF is of a certain size", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity pageSize( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file", required = true) MultipartFile inputFile, - @Parameter(description = "Standard Page Size", required = true) String standardPageSize, - @Parameter(description = "Comparison type", schema = @Schema(description = "The comparison type, accepts Greater, Equal, Less than", allowableValues = { - "Greater", "Equal", "Less" })) String comparator) - throws IOException, InterruptedException { + public ResponseEntity pageSize(@ModelAttribute PageSizeRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String standardPageSize = request.getStandardPageSize(); + String comparator = request.getComparator(); // Load the PDF PDDocument document = PDDocument.load(inputFile.getInputStream()); @@ -126,12 +130,10 @@ public class FilterController { @PostMapping(consumes = "multipart/form-data", value = "/filter-file-size") @Operation(summary = "Checks if a PDF is a set file size", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity fileSize( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file", required = true) MultipartFile inputFile, - @Parameter(description = "File Size", required = true) String fileSize, - @Parameter(description = "Comparison type", schema = @Schema(description = "The comparison type, accepts Greater, Equal, Less than", allowableValues = { - "Greater", "Equal", "Less" })) String comparator) - throws IOException, InterruptedException { + public ResponseEntity fileSize(@ModelAttribute FileSizeRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String fileSize = request.getFileSize(); + String comparator = request.getComparator(); // Get the file size long actualFileSize = inputFile.getSize(); @@ -159,12 +161,10 @@ public class FilterController { @PostMapping(consumes = "multipart/form-data", value = "/filter-page-rotation") @Operation(summary = "Checks if a PDF is of a certain rotation", description = "Input:PDF Output:Boolean Type:SISO") - public ResponseEntity pageRotation( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file", required = true) MultipartFile inputFile, - @Parameter(description = "Rotation in degrees", required = true) int rotation, - @Parameter(description = "Comparison type", schema = @Schema(description = "The comparison type, accepts Greater, Equal, Less than", allowableValues = { - "Greater", "Equal", "Less" })) String comparator) - throws IOException, InterruptedException { + public ResponseEntity pageRotation(@ModelAttribute PageRotationRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + int rotation = request.getRotation(); + String comparator = request.getComparator(); // Load the PDF PDDocument document = PDDocument.load(inputFile.getInputStream()); diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/AutoRenameController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/AutoRenameController.java similarity index 90% rename from src/main/java/stirling/software/SPDF/controller/api/other/AutoRenameController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/AutoRenameController.java index eb20f3bd..8059062c 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/AutoRenameController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/AutoRenameController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.IOException; import java.util.ArrayList; @@ -11,6 +11,7 @@ import org.apache.pdfbox.text.TextPosition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; @@ -20,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.misc.ExtractHeaderRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @Tag(name = "Other", description = "Other APIs") @@ -32,10 +34,9 @@ public class AutoRenameController { @PostMapping(consumes = "multipart/form-data", value = "/auto-rename") @Operation(summary = "Extract header from PDF file", description = "This endpoint accepts a PDF file and attempts to extract its title or header based on heuristics. Input:PDF Output:PDF Type:SISO") - public ResponseEntity extractHeader( - @RequestPart(value = "fileInput") @Parameter(description = "The input PDF file from which the header is to be extracted.", required = true) MultipartFile file, - @RequestParam(required = false, defaultValue = "false") @Parameter(description = "Flag indicating whether to use the first text as a fallback if no suitable title is found. Defaults to false.", required = false) Boolean useFirstTextAsFallback) - throws Exception { + public ResponseEntity extractHeader(@ModelAttribute ExtractHeaderRequest request) throws Exception { + MultipartFile file = request.getFileInput(); + Boolean useFirstTextAsFallback = request.getUseFirstTextAsFallback(); PDDocument document = PDDocument.load(file.getInputStream()); PDFTextStripper reader = new PDFTextStripper() { diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/AutoSplitPdfController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/AutoSplitPdfController.java similarity index 91% rename from src/main/java/stirling/software/SPDF/controller/api/other/AutoSplitPdfController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/AutoSplitPdfController.java index e3e56847..3ba81f78 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/AutoSplitPdfController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/AutoSplitPdfController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.DataBufferInt; @@ -16,6 +16,7 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.PDFRenderer; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -31,6 +32,7 @@ import com.google.zxing.common.HybridBinarizer; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import stirling.software.SPDF.model.api.misc.AutoSplitPdfRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -40,10 +42,9 @@ public class AutoSplitPdfController { @PostMapping(value = "/auto-split-pdf", consumes = "multipart/form-data") @Operation(summary = "Auto split PDF pages into separate documents", description = "This endpoint accepts a PDF file, scans each page for a specific QR code, and splits the document at the QR code boundaries. The output is a zip file containing each separate PDF document. Input:PDF Output:ZIP Type:SISO") - public ResponseEntity autoSplitPdf( - @RequestParam("fileInput") @Parameter(description = "The input PDF file which needs to be split into separate documents based on QR code boundaries.", required = true) MultipartFile file, - @RequestParam(value ="duplexMode",defaultValue = "false") @Parameter(description = "Flag indicating if the duplex mode is active, where the page after the divider also gets removed.", required = false) boolean duplexMode) - throws IOException { + public ResponseEntity autoSplitPdf(@ModelAttribute AutoSplitPdfRequest request) throws IOException { + MultipartFile file = request.getFileInput(); + boolean duplexMode = request.isDuplexMode(); InputStream inputStream = file.getInputStream(); PDDocument document = PDDocument.load(inputStream); diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java similarity index 87% rename from src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java index 4f505b73..5107d8c0 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.image.BufferedImage; import java.io.IOException; @@ -20,6 +20,7 @@ import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.text.PDFTextStripper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; @@ -29,6 +30,7 @@ import org.springframework.web.multipart.MultipartFile; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.misc.RemoveBlankPagesRequest; import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; @@ -43,16 +45,10 @@ public class BlankPageController { summary = "Remove blank pages from a PDF file", description = "This endpoint removes blank pages from a given PDF file. Users can specify the threshold and white percentage to tune the detection of blank pages. Input:PDF Output:PDF Type:SISO" ) - public ResponseEntity removeBlankPages( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input PDF file from which blank pages will be removed", required = true) - MultipartFile inputFile, - @RequestParam(defaultValue = "10", name = "threshold") - @Parameter(description = "The threshold value to determine blank pages", example = "10") - int threshold, - @RequestParam(defaultValue = "99.9", name = "whitePercent") - @Parameter(description = "The percentage of white color on a page to consider it as blank", example = "99.9") - float whitePercent) throws IOException, InterruptedException { + public ResponseEntity removeBlankPages(@ModelAttribute RemoveBlankPagesRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + int threshold = request.getThreshold(); + float whitePercent = request.getWhitePercent(); PDDocument document = null; try { diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/CompressController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java similarity index 93% rename from src/main/java/stirling/software/SPDF/controller/api/other/CompressController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java index 381a6821..89147056 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/CompressController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.Image; import java.awt.image.BufferedImage; @@ -22,6 +22,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; @@ -32,6 +33,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.misc.OptimizePdfRequest; import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; @@ -45,12 +47,11 @@ public class CompressController { @PostMapping(consumes = "multipart/form-data", value = "/compress-pdf") @Operation(summary = "Optimize PDF file", description = "This endpoint accepts a PDF file and optimizes it based on the provided parameters. Input:PDF Output:PDF Type:SISO") - public ResponseEntity optimizePdf( - @RequestPart(value = "fileInput") @Parameter(description = "The input PDF file to be optimized.", required = true) MultipartFile inputFile, - @RequestParam(required = false, value = "optimizeLevel") @Parameter(description = "The level of optimization to apply to the PDF file. Higher values indicate greater compression but may reduce quality.", schema = @Schema(allowableValues = { - "1", "2", "3", "4", "5" })) Integer optimizeLevel, - @RequestParam(value = "expectedOutputSize", required = false) @Parameter(description = "The expected output size, e.g. '100MB', '25KB', etc.", required = false) String expectedOutputSizeString) - throws Exception { + public ResponseEntity optimizePdf(@ModelAttribute OptimizePdfRequest request) throws Exception { + MultipartFile inputFile = request.getFileInput(); + Integer optimizeLevel = request.getOptimizeLevel(); + String expectedOutputSizeString = request.getExpectedOutputSizeString(); + if(expectedOutputSizeString == null && optimizeLevel == null) { throw new Exception("Both expected output size and optimize level are not specified"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java similarity index 95% rename from src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java index cb13682d..5a1bbf8a 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImageScansController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -33,6 +33,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.misc.ExtractImageScansRequest; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.WebResponseUtils; @@ -53,10 +54,10 @@ public class ExtractImageScansController { required = true, content = @Content( mediaType = "multipart/form-data", - schema = @Schema(implementation = MyForm.class) // This should represent your form's structure + schema = @Schema(implementation = ExtractImageScansRequest.class) // This should represent your form's structure ) ) - MyForm form) throws IOException, InterruptedException { + ExtractImageScansRequest form) throws IOException, InterruptedException { String fileName = form.getFileInput().getOriginalFilename(); String extension = fileName.substring(fileName.lastIndexOf(".") + 1); diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImagesController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java similarity index 98% rename from src/main/java/stirling/software/SPDF/controller/api/other/ExtractImagesController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java index c10dd7b4..206c78a2 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/ExtractImagesController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImagesController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.Graphics2D; import java.awt.Image; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/FakeScanControllerWIP.java b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java similarity index 99% rename from src/main/java/stirling/software/SPDF/controller/api/other/FakeScanControllerWIP.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java index 19c5aa5e..e3ec8d5e 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/FakeScanControllerWIP.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.awt.Color; import java.awt.geom.AffineTransform; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/MetadataController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/MetadataController.java similarity index 99% rename from src/main/java/stirling/software/SPDF/controller/api/other/MetadataController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/MetadataController.java index e3979d10..059db19d 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/MetadataController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/MetadataController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.IOException; import java.text.ParseException; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java similarity index 99% rename from src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java index d6009c8a..768493ab 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/OCRController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.File; import java.io.FileOutputStream; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/OverlayImageController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/OverlayImageController.java similarity index 98% rename from src/main/java/stirling/software/SPDF/controller/api/other/OverlayImageController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/OverlayImageController.java index 61768f6a..975e7628 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/OverlayImageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/OverlayImageController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.IOException; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/PageNumbersController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java similarity index 96% rename from src/main/java/stirling/software/SPDF/controller/api/other/PageNumbersController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java index 8e38bd10..2192d876 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/PageNumbersController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/RepairController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java similarity index 98% rename from src/main/java/stirling/software/SPDF/controller/api/other/RepairController.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java index 52644080..e9983902 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/RepairController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.io.IOException; import java.nio.file.Files; diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/ShowJavascript.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ShowJavascript.java similarity index 97% rename from src/main/java/stirling/software/SPDF/controller/api/other/ShowJavascript.java rename to src/main/java/stirling/software/SPDF/controller/api/misc/ShowJavascript.java index d812f5c8..08ac3e1b 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/ShowJavascript.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ShowJavascript.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.controller.api.misc; import java.nio.charset.StandardCharsets; import java.util.Map; diff --git a/src/main/java/stirling/software/SPDF/model/api/PDFComparison.java b/src/main/java/stirling/software/SPDF/model/api/PDFComparison.java new file mode 100644 index 00000000..5d7871b0 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/PDFComparison.java @@ -0,0 +1,19 @@ +package stirling.software.SPDF.model.api; + +import java.io.IOException; +import java.util.List; + +import org.apache.pdfbox.pdmodel.PDDocument; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.NoArgsConstructor; +import stirling.software.SPDF.utils.GeneralUtils; +@Data +@NoArgsConstructor +public class PDFComparison extends PDFFile { + + @Schema(description = "The comparison type, accepts Greater, Equal, Less than", allowableValues = { + "Greater", "Equal", "Less" }) + private String comparator; + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/PDFComparisonAndCount.java b/src/main/java/stirling/software/SPDF/model/api/PDFComparisonAndCount.java new file mode 100644 index 00000000..8779ba57 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/PDFComparisonAndCount.java @@ -0,0 +1,18 @@ +package stirling.software.SPDF.model.api; + +import java.io.IOException; +import java.util.List; + +import org.apache.pdfbox.pdmodel.PDDocument; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.NoArgsConstructor; +import stirling.software.SPDF.utils.GeneralUtils; +@Data +@NoArgsConstructor +public class PDFComparisonAndCount extends PDFComparison { + @Schema(description = "Count") + private String pageCount; + + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java new file mode 100644 index 00000000..4dc4e137 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api.filter; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFWithPageNums; + +@Data +public class ContainsTextRequest extends PDFWithPageNums { + + @Schema(description = "The text to check for", required = true) + private String text; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java new file mode 100644 index 00000000..cffcd9a4 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java @@ -0,0 +1,15 @@ +package stirling.software.SPDF.model.api.filter; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFComparison; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class FileSizeRequest extends PDFComparison { + + @Schema(description = "File Size", required = true) + private String fileSize; + + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java new file mode 100644 index 00000000..8f36ae5d --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java @@ -0,0 +1,14 @@ +package stirling.software.SPDF.model.api.filter; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFComparison; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class PageRotationRequest extends PDFComparison { + + @Schema(description = "Rotation in degrees", required = true) + private int rotation; + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java new file mode 100644 index 00000000..0184ac90 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java @@ -0,0 +1,15 @@ +package stirling.software.SPDF.model.api.filter; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFComparison; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class PageSizeRequest extends PDFComparison { + + @Schema(description = "Standard Page Size", required = true) + private String standardPageSize; + + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java new file mode 100644 index 00000000..822eb7a6 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api.misc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class AutoSplitPdfRequest extends PDFFile { + + @Schema(description = "Flag indicating if the duplex mode is active, where the page after the divider also gets removed.", required = false, defaultValue = "false") + private boolean duplexMode; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java new file mode 100644 index 00000000..d05b865e --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api.misc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class ExtractHeaderRequest extends PDFFile { + + @Schema(description = "Flag indicating whether to use the first text as a fallback if no suitable title is found. Defaults to false.", required = false, defaultValue = "false") + private Boolean useFirstTextAsFallback; +} diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java similarity index 91% rename from src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java rename to src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java index 1938493a..8a12fc47 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java @@ -1,4 +1,4 @@ -package stirling.software.SPDF.controller.api.other; +package stirling.software.SPDF.model.api.misc; import org.springframework.web.multipart.MultipartFile; @@ -6,7 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data -public class MyForm { +public class ExtractImageScansRequest { @Schema(description = "The input file containing image scans", required = true) private MultipartFile fileInput; diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/OptimizePdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/OptimizePdfRequest.java new file mode 100644 index 00000000..65028a7f --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/misc/OptimizePdfRequest.java @@ -0,0 +1,16 @@ +package stirling.software.SPDF.model.api.misc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class OptimizePdfRequest extends PDFFile { + + @Schema(description = "The level of optimization to apply to the PDF file. Higher values indicate greater compression but may reduce quality.", + allowableValues = { "1", "2", "3", "4", "5" }) + private Integer optimizeLevel; + + @Schema(description = "The expected output size, e.g. '100MB', '25KB', etc.") + private String expectedOutputSizeString; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/RemoveBlankPagesRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/RemoveBlankPagesRequest.java new file mode 100644 index 00000000..a7a92897 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/misc/RemoveBlankPagesRequest.java @@ -0,0 +1,15 @@ +package stirling.software.SPDF.model.api.misc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class RemoveBlankPagesRequest extends PDFFile { + + @Schema(description = "The threshold value to determine blank pages", example = "10", defaultValue = "10") + private int threshold; + + @Schema(description = "The percentage of white color on a page to consider it as blank", example = "99.9", defaultValue = "99.9") + private float whitePercent; +}