From b1fd798a5cbf02fd9f804103dd6a3df602477659 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:25:27 +0100 Subject: [PATCH] init --- build.gradle | 2 + .../SPDF/controller/api/CropController.java | 19 ++++---- .../SPDF/controller/api/MergeController.java | 19 +++----- .../api/MultiPageLayoutController.java | 11 +++-- .../api/RearrangePagesPDFController.java | 32 +++++-------- .../controller/api/RotationController.java | 12 ++--- .../controller/api/ScalePagesController.java | 14 +++--- .../controller/api/SplitPDFController.java | 31 +++--------- .../api/ToSinglePageController.java | 11 ++--- .../api/converters/ConvertEpubToPdf.java | 7 ++- .../api/converters/ConvertHtmlToPDF.java | 6 ++- .../converters/ConvertImgPDFController.java | 46 +++++++----------- .../api/converters/ConvertMarkdownToPdf.java | 7 ++- .../converters/ConvertOfficeController.java | 13 ++--- .../api/converters/ConvertPDFToOffice.java | 43 +++++++++-------- .../api/converters/ConvertPDFToPDFA.java | 9 ++-- .../api/converters/ConvertWebsiteToPDF.java | 8 ++-- .../other/ExtractImageScansController.java | 48 ++++++++----------- .../SPDF/controller/api/other/MyForm.java | 27 +++++++++++ .../api/security/CertSignController.java | 2 +- .../software/SPDF/model/SortTypes.java | 4 ++ .../software/SPDF/model/api/GeneralFile.java | 13 +++++ .../software/SPDF/model/api/ImageFile.java | 12 +++++ .../SPDF/model/api/MultiplePDFFiles.java | 11 +++++ .../software/SPDF/model/api/PDFFile.java | 11 +++++ .../SPDF/model/api/PDFWithPageNums.java | 36 ++++++++++++++ .../api/converters/ConvertToImageRequest.java | 22 +++++++++ .../api/converters/ConvertToPdfRequest.java | 21 ++++++++ .../converters/PdfToPresentationRequest.java | 13 +++++ .../api/converters/PdfToTextOrRTFRequest.java | 12 +++++ .../api/converters/PdfToWordRequest.java | 12 +++++ .../model/api/converters/UrlToPdfRequest.java | 11 +++++ .../SPDF/model/api/general/CropPdfForm.java | 26 ++++++++++ .../general/MergeMultiplePagesRequest.java | 13 +++++ .../model/api/general/MergePdfsRequest.java | 20 ++++++++ .../api/general/RearrangePagesRequest.java | 23 +++++++++ .../model/api/general/RotatePDFRequest.java | 13 +++++ .../model/api/general/ScalePagesRequest.java | 20 ++++++++ .../software/SPDF/utils/GeneralUtils.java | 3 ++ 39 files changed, 468 insertions(+), 195 deletions(-) create mode 100644 src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java create mode 100644 src/main/java/stirling/software/SPDF/model/SortTypes.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/GeneralFile.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/ImageFile.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/MultiplePDFFiles.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/PDFFile.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/PDFWithPageNums.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/ConvertToPdfRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/PdfToPresentationRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/PdfToTextOrRTFRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/PdfToWordRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/CropPdfForm.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/MergeMultiplePagesRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/MergePdfsRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/RearrangePagesRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/RotatePDFRequest.java create mode 100644 src/main/java/stirling/software/SPDF/model/api/general/ScalePagesRequest.java diff --git a/build.gradle b/build.gradle index b628a2d4..bc62189e 100644 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,8 @@ dependencies { implementation 'com.github.vladimir-bukhtoyarov:bucket4j-core:7.6.0' developmentOnly("org.springframework.boot:spring-boot-devtools") + compileOnly 'org.projectlombok:lombok:1.18.28' + annotationProcessor 'org.projectlombok:lombok:1.18.28' } diff --git a/src/main/java/stirling/software/SPDF/controller/api/CropController.java b/src/main/java/stirling/software/SPDF/controller/api/CropController.java index 9e8cf1fe..38d68420 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/CropController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/CropController.java @@ -13,6 +13,7 @@ import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; 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.RestController; @@ -22,6 +23,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.general.CropPdfForm; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -32,18 +34,13 @@ public class CropController { @PostMapping(value = "/crop", consumes = "multipart/form-data") @Operation(summary = "Crops a PDF document", description = "This operation takes an input PDF file and crops it according to the given coordinates. Input:PDF Output:PDF Type:SISO") - public ResponseEntity cropPdf( - @Parameter(description = "The input PDF file", required = true) @RequestParam("fileInput") MultipartFile file, - @Parameter(description = "The x-coordinate of the top-left corner of the crop area", required = true, schema = @Schema(type = "number")) @RequestParam("x") float x, - @Parameter(description = "The y-coordinate of the top-left corner of the crop area", required = true, schema = @Schema(type = "number")) @RequestParam("y") float y, - @Parameter(description = "The width of the crop area", required = true, schema = @Schema(type = "number")) @RequestParam("width") float width, - @Parameter(description = "The height of the crop area", required = true, schema = @Schema(type = "number")) @RequestParam("height") float height) + public ResponseEntity cropPdf(@ModelAttribute CropPdfForm form) throws IOException { + - -PDDocument sourceDocument = PDDocument.load(new ByteArrayInputStream(file.getBytes())); +PDDocument sourceDocument = PDDocument.load(new ByteArrayInputStream(form.getFileInput().getBytes())); PDDocument newDocument = new PDDocument(); @@ -65,7 +62,7 @@ for (int i = 0; i < totalPages; i++) { contentStream.saveGraphicsState(); // Define the crop area - contentStream.addRect(x, y, width, height); + contentStream.addRect(form.getX(), form.getY(), form.getWidth(), form.getHeight()); contentStream.clip(); // Draw the entire formXObject @@ -76,7 +73,7 @@ for (int i = 0; i < totalPages; i++) { contentStream.close(); // Now, set the new page's media box to the cropped size - newPage.setMediaBox(new PDRectangle(x, y, width, height)); + newPage.setMediaBox(new PDRectangle(form.getX(), form.getY(), form.getWidth(), form.getHeight())); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -85,7 +82,7 @@ newDocument.close(); sourceDocument.close(); byte[] pdfContent = baos.toByteArray(); -return WebResponseUtils.bytesToWebResponse(pdfContent, file.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_cropped.pdf"); +return WebResponseUtils.bytesToWebResponse(pdfContent, form.getFileInput().getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_cropped.pdf"); } } diff --git a/src/main/java/stirling/software/SPDF/controller/api/MergeController.java b/src/main/java/stirling/software/SPDF/controller/api/MergeController.java index e51db38e..03bf4066 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/MergeController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/MergeController.java @@ -15,6 +15,7 @@ import org.apache.pdfbox.pdmodel.PDPage; 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; @@ -25,6 +26,8 @@ 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.general.CropPdfForm; +import stirling.software.SPDF.model.api.general.MergePdfsRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -88,20 +91,10 @@ private Comparator getSortComparator(String sortType) { @PostMapping(consumes = "multipart/form-data", value = "/merge-pdfs") @Operation(summary = "Merge multiple PDF files into one", description = "This endpoint merges multiple PDF files into a single PDF file. The merged file will contain all pages from the input files in the order they were provided. Input:PDF Output:PDF Type:MISO") -public ResponseEntity mergePdfs( - @RequestPart(required = true, value = "fileInput") MultipartFile[] files, - @RequestParam(value = "sortType", defaultValue = "orderProvided") - @Parameter(schema = @Schema(description = "The type of sorting to be applied on the input files before merging.", - allowableValues = { - "orderProvided", - "byFileName", - "byDateModified", - "byDateCreated", - "byPDFTitle" - })) - String sortType) throws IOException { +public ResponseEntity mergePdfs(@ModelAttribute MergePdfsRequest form) throws IOException { - Arrays.sort(files, getSortComparator(sortType)); + MultipartFile[] files = form.getFileInput(); + Arrays.sort(files, getSortComparator(form.getSortType())); List documents = new ArrayList<>(); for (MultipartFile file : files) { diff --git a/src/main/java/stirling/software/SPDF/controller/api/MultiPageLayoutController.java b/src/main/java/stirling/software/SPDF/controller/api/MultiPageLayoutController.java index 738542a0..12c262cd 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/MultiPageLayoutController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/MultiPageLayoutController.java @@ -14,6 +14,7 @@ import org.apache.pdfbox.util.Matrix; 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.RestController; @@ -23,6 +24,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.general.MergeMultiplePagesRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -36,12 +38,11 @@ public class MultiPageLayoutController { summary = "Merge multiple pages of a PDF document into a single page", description = "This operation takes an input PDF file and the number of pages to merge into a single sheet in the output PDF file. Input:PDF Output:PDF Type:SISO" ) - public ResponseEntity mergeMultiplePagesIntoOne( - @Parameter(description = "The input PDF file", required = true) @RequestParam("fileInput") MultipartFile file, - @Parameter(description = "The number of pages to fit onto a single sheet in the output PDF. Acceptable values are 2, 3, 4, 9, 16.", required = true, schema = @Schema(type = "integer", allowableValues = { - "2", "3", "4", "9", "16" })) @RequestParam("pagesPerSheet") int pagesPerSheet) + public ResponseEntity mergeMultiplePagesIntoOne(@ModelAttribute MergeMultiplePagesRequest request) throws IOException { - + + int pagesPerSheet = request.getPagesPerSheet(); + MultipartFile file = request.getFileInput(); if (pagesPerSheet != 2 && pagesPerSheet != 3 && pagesPerSheet != (int) Math.sqrt(pagesPerSheet) * Math.sqrt(pagesPerSheet)) { throw new IllegalArgumentException("pagesPerSheet must be 2, 3 or a perfect square"); } diff --git a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java index 78df1f41..294df38d 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/RearrangePagesPDFController.java @@ -9,6 +9,7 @@ import org.apache.pdfbox.pdmodel.PDPage; 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; @@ -21,7 +22,8 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.WebResponseUtils; - +import stirling.software.SPDF.model.SortTypes; +import stirling.software.SPDF.model.api.general.RearrangePagesRequest; @RestController @Tag(name = "General", description = "General APIs") public class RearrangePagesPDFController { @@ -51,9 +53,7 @@ public class RearrangePagesPDFController { } - private enum CustomMode { - REVERSE_ORDER, DUPLEX_SORT, BOOKLET_SORT, SIDE_STITCH_BOOKLET_SORT, ODD_EVEN_SPLIT, REMOVE_FIRST, REMOVE_LAST, REMOVE_FIRST_AND_LAST, - } + private List removeFirst(int totalPages) { if (totalPages <= 1) @@ -137,9 +137,9 @@ public class RearrangePagesPDFController { return newPageOrder; } - private List processCustomMode(String customMode, int totalPages) { + private List processSortTypes(String sortTypes, int totalPages) { try { - CustomMode mode = CustomMode.valueOf(customMode.toUpperCase()); + SortTypes mode = SortTypes.valueOf(sortTypes.toUpperCase()); switch (mode) { case REVERSE_ORDER: return reverseOrder(totalPages); @@ -168,16 +168,10 @@ public class RearrangePagesPDFController { @PostMapping(consumes = "multipart/form-data", value = "/rearrange-pages") @Operation(summary = "Rearrange pages in a PDF file", description = "This endpoint rearranges pages in a given PDF file based on the specified page order or custom mode. Users can provide a page order as a comma-separated list of page numbers or page ranges, or a custom mode. Input:PDF Output:PDF") - public ResponseEntity rearrangePages( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to rearrange pages") MultipartFile pdfFile, - @RequestParam(required = false, value = "pageOrder") @Parameter(description = "The new page order as a comma-separated list of page numbers, page ranges (e.g., '1,3,5-7'), or functions in the format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a constant (e.g., '2n+1', '3n', '6n-5')") String pageOrder, - @RequestParam(required = false, value = "customMode") @Parameter(schema = @Schema(implementation = CustomMode.class, description = "The custom mode for page rearrangement. " - + "Valid values are:\n" + "REVERSE_ORDER: Reverses the order of all pages.\n" - + "DUPLEX_SORT: Sorts pages as if all fronts were scanned then all backs in reverse (1, n, 2, n-1, ...). " - + "BOOKLET_SORT: Arranges pages for booklet printing (last, first, second, second last, ...).\n" - + "ODD_EVEN_SPLIT: Splits and arranges pages into odd and even numbered pages.\n" - + "REMOVE_FIRST: Removes the first page.\n" + "REMOVE_LAST: Removes the last page.\n" - + "REMOVE_FIRST_AND_LAST: Removes both the first and the last pages.\n")) String customMode) { + public ResponseEntity rearrangePages(@ModelAttribute RearrangePagesRequest request) throws IOException { + MultipartFile pdfFile = request.getFileInput(); + String pageOrder = request.getPageNumbers(); + String sortType = request.getCustomMode(); try { // Load the input PDF PDDocument document = PDDocument.load(pdfFile.getInputStream()); @@ -186,10 +180,10 @@ public class RearrangePagesPDFController { String[] pageOrderArr = pageOrder != null ? pageOrder.split(",") : new String[0]; int totalPages = document.getNumberOfPages(); System.out.println("pageOrder=" + pageOrder); - System.out.println("customMode length =" + customMode.length()); + System.out.println("SortTypes length =" + sortType.length()); List newPageOrder; - if (customMode != null && customMode.length() > 0) { - newPageOrder = processCustomMode(customMode, totalPages); + if (sortType != null && sortType.length() > 0) { + newPageOrder = processSortTypes(sortType, totalPages); } else { newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages); } diff --git a/src/main/java/stirling/software/SPDF/controller/api/RotationController.java b/src/main/java/stirling/software/SPDF/controller/api/RotationController.java index 916d2afb..ef32df4e 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/RotationController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/RotationController.java @@ -8,6 +8,7 @@ import org.apache.pdfbox.pdmodel.PDPageTree; 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; @@ -17,6 +18,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.general.RotatePDFRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -31,13 +33,9 @@ public class RotationController { description = "This endpoint rotates a given PDF file by a specified angle. The angle must be a multiple of 90. Input:PDF Output:PDF Type:SISO" ) public ResponseEntity rotatePDF( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The PDF file to be rotated", required = true) - MultipartFile pdfFile, - @RequestParam("angle") - @Parameter(description = "The angle by which to rotate the PDF file. This should be a multiple of 90.", example = "90", required = true) - Integer angle) throws IOException { - + @ModelAttribute RotatePDFRequest request) throws IOException { + MultipartFile pdfFile = request.getFileInput(); + Integer angle = request.getAngle(); // Load the PDF document PDDocument document = PDDocument.load(pdfFile.getBytes()); diff --git a/src/main/java/stirling/software/SPDF/controller/api/ScalePagesController.java b/src/main/java/stirling/software/SPDF/controller/api/ScalePagesController.java index 2f1cde7d..2dcb26af 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/ScalePagesController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/ScalePagesController.java @@ -15,6 +15,7 @@ import org.apache.pdfbox.util.Matrix; 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.RestController; @@ -24,6 +25,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.general.ScalePagesRequest; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @Tag(name = "General", description = "General APIs") @@ -33,14 +35,10 @@ public class ScalePagesController { @PostMapping(value = "/scale-pages", consumes = "multipart/form-data") @Operation(summary = "Change the size of a PDF page/document", description = "This operation takes an input PDF file and the size to scale the pages to in the output PDF file. Input:PDF Output:PDF Type:SISO") - public ResponseEntity scalePages( - @Parameter(description = "The input PDF file", required = true) @RequestParam("fileInput") MultipartFile file, - @Parameter(description = "The scale of pages in the output PDF. Acceptable values are A0-A10, B0-B9, LETTER, TABLOID, LEDGER, LEGAL, EXECUTIVE.", required = true, schema = @Schema(type = "string", allowableValues = { - "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "B0", "B1", "B2", "B3", "B4", - "B5", "B6", "B7", "B8", "B9", "LETTER", "TABLOID", "LEDGER", "LEGAL", - "EXECUTIVE" })) @RequestParam("pageSize") String targetPDRectangle, - @Parameter(description = "The scale of the content on the pages of the output PDF. Acceptable values are floats.", required = true, schema = @Schema(type = "integer")) @RequestParam("scaleFactor") float scaleFactor) - throws IOException { + public ResponseEntity scalePages(@ModelAttribute ScalePagesRequest request) throws IOException { + MultipartFile file = request.getFileInput(); + String targetPDRectangle = request.getTargetPDRectangle(); + float scaleFactor = request.getScaleFactor(); Map sizeMap = new HashMap<>(); // Add A0 - A10 diff --git a/src/main/java/stirling/software/SPDF/controller/api/SplitPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/SplitPDFController.java index abc201ab..fe3a1cc5 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/SplitPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/SplitPDFController.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.RequestPart; @@ -26,6 +27,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.PDFWithPageNums; import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.WebResponseUtils; @@ -38,35 +40,14 @@ public class SplitPDFController { @PostMapping(consumes = "multipart/form-data", value = "/split-pages") @Operation(summary = "Split a PDF file into separate documents", description = "This endpoint splits a given PDF file into separate documents based on the specified page numbers or ranges. Users can specify pages using individual numbers, ranges, or 'all' for every page. Input:PDF Output:PDF Type:SIMO") - public ResponseEntity splitPdf( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input PDF file to be split") - MultipartFile file, - @RequestParam("pages") - @Parameter(description = "The pages to be included in separate documents. Specify individual page numbers (e.g., '1,3,5'), ranges (e.g., '1-3,5-7'), or 'all' for every page.") - String pages) throws IOException { - // parse user input - + public ResponseEntity splitPdf(@ModelAttribute PDFWithPageNums request) throws IOException { + MultipartFile file = request.getFileInput(); + String pages = request.getPageNumbers(); // open the pdf document InputStream inputStream = file.getInputStream(); PDDocument document = PDDocument.load(inputStream); - List pageNumbers = new ArrayList<>(); - pages = pages.replaceAll("\\s+", ""); // remove whitespaces - if (pages.toLowerCase().equals("all")) { - for (int i = 0; i < document.getNumberOfPages(); i++) { - pageNumbers.add(i); - } - } else { - String[] splitPoints = pages.split(","); - for (String splitPoint : splitPoints) { - List orderedPages = GeneralUtils.parsePageList(new String[] {splitPoint}, document.getNumberOfPages()); - pageNumbers.addAll(orderedPages); - } - // Add the last page as a split point - pageNumbers.add(document.getNumberOfPages() - 1); - } - + List pageNumbers = request.getPageNumbersList(document); logger.info("Splitting PDF into pages: {}", pageNumbers.stream().map(String::valueOf).collect(Collectors.joining(","))); // split the document diff --git a/src/main/java/stirling/software/SPDF/controller/api/ToSinglePageController.java b/src/main/java/stirling/software/SPDF/controller/api/ToSinglePageController.java index e46cb55a..ea64d55b 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/ToSinglePageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/ToSinglePageController.java @@ -13,6 +13,7 @@ import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; 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.RequestPart; import org.springframework.web.bind.annotation.RestController; @@ -21,6 +22,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.PDFFile; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @Tag(name = "General", description = "General APIs") @@ -34,13 +36,10 @@ public class ToSinglePageController { summary = "Convert a multi-page PDF into a single long page PDF", description = "This endpoint converts a multi-page PDF document into a single paged PDF document. The width of the single page will be same as the input's width, but the height will be the sum of all the pages' heights. Input:PDF Output:PDF Type:SISO" ) - public ResponseEntity pdfToSinglePage( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input multi-page PDF file to be converted into a single page", required = true) - MultipartFile file) throws IOException { + public ResponseEntity pdfToSinglePage(@ModelAttribute PDFFile request) throws IOException { // Load the source document - PDDocument sourceDocument = PDDocument.load(file.getInputStream()); + PDDocument sourceDocument = PDDocument.load(request.getFileInput().getInputStream()); // Calculate total height and max width float totalHeight = 0; @@ -79,7 +78,7 @@ public class ToSinglePageController { sourceDocument.close(); byte[] result = baos.toByteArray(); - return WebResponseUtils.bytesToWebResponse(result, file.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_singlePage.pdf"); + return WebResponseUtils.bytesToWebResponse(result, request.getFileInput().getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_singlePage.pdf"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java index 21f4612b..77262cce 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java @@ -14,6 +14,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; 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; @@ -26,6 +27,8 @@ import org.xml.sax.InputSource; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.GeneralFile; +import stirling.software.SPDF.model.api.PDFFile; import stirling.software.SPDF.utils.FileToPdf; import stirling.software.SPDF.utils.WebResponseUtils; @@ -40,9 +43,9 @@ public class ConvertEpubToPdf { description = "This endpoint takes an EPUB file input and converts it to a single PDF." ) public ResponseEntity epubToSinglePdf( - @RequestPart(required = true, value = "fileInput") MultipartFile fileInput) + @ModelAttribute GeneralFile request) throws Exception { - + MultipartFile fileInput = request.getFileInput(); if (fileInput == null) { throw new IllegalArgumentException("Please provide an EPUB file for conversion."); } diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java index 762cbe6b..d9308d09 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java @@ -3,6 +3,7 @@ package stirling.software.SPDF.controller.api.converters; import java.io.IOException; 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; @@ -10,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.GeneralFile; import stirling.software.SPDF.utils.FileToPdf; import stirling.software.SPDF.utils.WebResponseUtils; @@ -24,7 +26,9 @@ public class ConvertHtmlToPDF { description = "This endpoint takes an HTML or ZIP file input and converts it to a PDF format." ) public ResponseEntity HtmlToPdf( - @RequestPart(required = true, value = "fileInput") MultipartFile fileInput) throws IOException, InterruptedException { + @ModelAttribute GeneralFile request) + throws Exception { + MultipartFile fileInput = request.getFileInput(); if (fileInput == null) { throw new IllegalArgumentException("Please provide an HTML or ZIP file for conversion."); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java index d4964196..5a4dab2c 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java @@ -11,6 +11,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; 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.RequestPart; @@ -21,6 +22,8 @@ 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.converters.ConvertToImageRequest; +import stirling.software.SPDF.model.api.converters.ConvertToPdfRequest; import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.WebResponseUtils; @RestController @@ -32,23 +35,13 @@ public class ConvertImgPDFController { @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-img") @Operation(summary = "Convert PDF to image(s)", description = "This endpoint converts a PDF file to image(s) with the specified image format, color type, and DPI. Users can choose to get a single image or multiple images. Input:PDF Output:Image Type:SI-Conditional") - public ResponseEntity convertToImage( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input PDF file to be converted") - MultipartFile file, - @RequestParam("imageFormat") - @Parameter(description = "The output image format", schema = @Schema(allowableValues = {"png", "jpeg", "jpg", "gif"})) - String imageFormat, - @RequestParam("singleOrMultiple") - @Parameter(description = "Choose between a single image containing all pages or separate images for each page", schema = @Schema(allowableValues = {"single", "multiple"})) - String singleOrMultiple, - @RequestParam("colorType") - @Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"color", "greyscale", "blackwhite"})) - String colorType, - @RequestParam("dpi") - @Parameter(description = "The DPI (dots per inch) for the output image(s)") - String dpi) throws IOException { - + public ResponseEntity convertToImage(@ModelAttribute ConvertToImageRequest request) throws IOException { + MultipartFile file = request.getFileInput(); + String imageFormat = request.getImageFormat(); + String singleOrMultiple = request.getSingleOrMultiple(); + String colorType = request.getColorType(); + String dpi = request.getDpi(); + byte[] pdfBytes = file.getBytes(); ImageType colorTypeResult = ImageType.RGB; if ("greyscale".equals(colorType)) { @@ -86,19 +79,12 @@ public class ConvertImgPDFController { @PostMapping(consumes = "multipart/form-data", value = "/img-to-pdf") @Operation(summary = "Convert images to a PDF file", description = "This endpoint converts one or more images to a PDF file. Users can specify whether to stretch the images to fit the PDF page, and whether to automatically rotate the images. Input:Image Output:PDF Type:SISO?") - public ResponseEntity convertToPdf( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input images to be converted to a PDF file") - MultipartFile[] file, - @RequestParam(defaultValue = "false", name = "stretchToFit") - @Parameter(description = "Whether to stretch the images to fit the PDF page or maintain the aspect ratio", example = "false") - boolean stretchToFit, - @RequestParam("colorType") - @Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"color", "greyscale", "blackwhite"})) - String colorType, - @RequestParam(defaultValue = "false", name = "autoRotate") - @Parameter(description = "Whether to automatically rotate the images to better fit the PDF page", example = "true") - boolean autoRotate) throws IOException { + public ResponseEntity convertToPdf(@ModelAttribute ConvertToPdfRequest request) throws IOException { + MultipartFile[] file = request.getFileInput(); + boolean stretchToFit = request.isStretchToFit(); + String colorType = request.getColorType(); + boolean autoRotate = request.isAutoRotate(); + // Convert the file to PDF and get the resulting bytes byte[] bytes = PdfUtils.imageToPdf(file, stretchToFit, autoRotate, colorType); return WebResponseUtils.bytesToWebResponse(bytes, file[0].getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_converted.pdf"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java index c1bc1b73..02ff1e27 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java @@ -6,6 +6,7 @@ import org.commonmark.node.Node; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; 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; @@ -13,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import stirling.software.SPDF.model.api.GeneralFile; import stirling.software.SPDF.utils.FileToPdf; import stirling.software.SPDF.utils.WebResponseUtils; @@ -26,8 +28,9 @@ public class ConvertMarkdownToPdf { description = "This endpoint takes a Markdown file input, converts it to HTML, and then to PDF format." ) public ResponseEntity markdownToPdf( - @RequestPart(required = true, value = "fileInput") MultipartFile fileInput) - throws IOException, InterruptedException { + @ModelAttribute GeneralFile request) + throws Exception { + MultipartFile fileInput = request.getFileInput(); if (fileInput == null) { throw new IllegalArgumentException("Please provide a Markdown file for conversion."); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java index 3b9f278f..9ee5cdd5 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java @@ -10,6 +10,7 @@ import java.util.List; import org.apache.commons.io.FilenameUtils; 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; @@ -18,6 +19,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.GeneralFile; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.WebResponseUtils; @@ -63,14 +65,9 @@ public class ConvertOfficeController { summary = "Convert a file to a PDF using LibreOffice", description = "This endpoint converts a given file to a PDF using LibreOffice API Input:Any Output:PDF Type:SISO" ) - public ResponseEntity processFileToPDF( - @RequestPart(required = true, value = "fileInput") - @Parameter( - description = "The input file to be converted to a PDF file using LibreOffice", - required = true - ) - MultipartFile inputFile - ) throws IOException, InterruptedException { + public ResponseEntity processFileToPDF(@ModelAttribute GeneralFile request) + throws Exception { + MultipartFile inputFile = request.getFileInput(); // unused but can start server instance if startup time is to long // LibreOfficeListener.getInstance().start(); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToOffice.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToOffice.java index 7c99ee4d..b61549ff 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToOffice.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToOffice.java @@ -3,6 +3,7 @@ package stirling.software.SPDF.controller.api.converters; import java.io.IOException; 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; @@ -13,6 +14,11 @@ 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.GeneralFile; +import stirling.software.SPDF.model.api.PDFFile; +import stirling.software.SPDF.model.api.converters.PdfToPresentationRequest; +import stirling.software.SPDF.model.api.converters.PdfToTextOrRTFRequest; +import stirling.software.SPDF.model.api.converters.PdfToWordRequest; import stirling.software.SPDF.utils.PDFToFile; @RestController @@ -21,51 +27,46 @@ public class ConvertPDFToOffice { @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-html") @Operation(summary = "Convert PDF to HTML", description = "This endpoint converts a PDF file to HTML format. Input:PDF Output:HTML Type:SISO") - public ResponseEntity processPdfToHTML( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to be converted to HTML format", required = true) MultipartFile inputFile) - throws IOException, InterruptedException { + public ResponseEntity processPdfToHTML(@ModelAttribute PDFFile request) + throws Exception { + MultipartFile inputFile = request.getFileInput(); PDFToFile pdfToFile = new PDFToFile(); return pdfToFile.processPdfToOfficeFormat(inputFile, "html", "writer_pdf_import"); } @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-presentation") @Operation(summary = "Convert PDF to Presentation format", description = "This endpoint converts a given PDF file to a Presentation format. Input:PDF Output:PPT Type:SISO") - public ResponseEntity processPdfToPresentation( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file") MultipartFile inputFile, - @RequestParam("outputFormat") @Parameter(description = "The output Presentation format", schema = @Schema(allowableValues = { - "ppt", "pptx", "odp" })) String outputFormat) - throws IOException, InterruptedException { + public ResponseEntity processPdfToPresentation(@ModelAttribute PdfToPresentationRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String outputFormat = request.getOutputFormat(); PDFToFile pdfToFile = new PDFToFile(); return pdfToFile.processPdfToOfficeFormat(inputFile, outputFormat, "impress_pdf_import"); } @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-text") @Operation(summary = "Convert PDF to Text or RTF format", description = "This endpoint converts a given PDF file to Text or RTF format. Input:PDF Output:TXT Type:SISO") - public ResponseEntity processPdfToRTForTXT( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file") MultipartFile inputFile, - @RequestParam("outputFormat") @Parameter(description = "The output Text or RTF format", schema = @Schema(allowableValues = { - "rtf", "txt:Text" })) String outputFormat) - throws IOException, InterruptedException { + public ResponseEntity processPdfToRTForTXT(@ModelAttribute PdfToTextOrRTFRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String outputFormat = request.getOutputFormat(); + PDFToFile pdfToFile = new PDFToFile(); return pdfToFile.processPdfToOfficeFormat(inputFile, outputFormat, "writer_pdf_import"); } @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-word") @Operation(summary = "Convert PDF to Word document", description = "This endpoint converts a given PDF file to a Word document format. Input:PDF Output:WORD Type:SISO") - public ResponseEntity processPdfToWord( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file") MultipartFile inputFile, - @RequestParam("outputFormat") @Parameter(description = "The output Word document format", schema = @Schema(allowableValues = { - "doc", "docx", "odt" })) String outputFormat) - throws IOException, InterruptedException { + public ResponseEntity processPdfToWord(@ModelAttribute PdfToWordRequest request) throws IOException, InterruptedException { + MultipartFile inputFile = request.getFileInput(); + String outputFormat = request.getOutputFormat(); PDFToFile pdfToFile = new PDFToFile(); return pdfToFile.processPdfToOfficeFormat(inputFile, outputFormat, "writer_pdf_import"); } @PostMapping(consumes = "multipart/form-data", value = "/pdf-to-xml") @Operation(summary = "Convert PDF to XML", description = "This endpoint converts a PDF file to an XML file. Input:PDF Output:XML Type:SISO") - public ResponseEntity processPdfToXML( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to be converted to an XML file", required = true) MultipartFile inputFile) - throws IOException, InterruptedException { + public ResponseEntity processPdfToXML(@ModelAttribute PDFFile request) + throws Exception { + MultipartFile inputFile = request.getFileInput(); PDFToFile pdfToFile = new PDFToFile(); return pdfToFile.processPdfToOfficeFormat(inputFile, "xml", "writer_pdf_import"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java index 6a99090b..ca83d4ed 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; 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,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.PDFFile; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.WebResponseUtils; @@ -28,10 +30,9 @@ public class ConvertPDFToPDFA { summary = "Convert a PDF to a PDF/A", description = "This endpoint converts a PDF file to a PDF/A file. PDF/A is a format designed for long-term archiving of digital documents. Input:PDF Output:PDF Type:SISO" ) - public ResponseEntity pdfToPdfA( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input PDF file to be converted to a PDF/A file", required = true) - MultipartFile inputFile) throws IOException, InterruptedException { + public ResponseEntity pdfToPdfA(@ModelAttribute PDFFile request) + throws Exception { + MultipartFile inputFile = request.getFileInput(); // Save the uploaded file to a temporary location Path tempInputFile = Files.createTempFile("input_", ".pdf"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java index 2268ead5..3d4fd368 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; 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; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController; 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.converters.UrlToPdfRequest; import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; @@ -28,10 +30,8 @@ public class ConvertWebsiteToPDF { summary = "Convert a URL to a PDF", description = "This endpoint fetches content from a URL and converts it to a PDF format." ) - public ResponseEntity urlToPdf( - @RequestParam(required = true, value = "urlInput") - @Parameter(description = "The input URL to be converted to a PDF file", required = true) - String URL) throws IOException, InterruptedException { + public ResponseEntity urlToPdf(@ModelAttribute UrlToPdfRequest request) throws IOException, InterruptedException { + String URL = request.getUrlInput(); // Validate the URL format if(!URL.matches("^https?://.*") || !GeneralUtils.isValidURL(URL)) { 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 55ff446c..cb13682d 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 @@ -30,12 +30,14 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; 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.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.WebResponseUtils; - +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; @RestController @Tag(name = "Other", description = "Other APIs") public class ExtractImageScansController { @@ -46,26 +48,16 @@ public class ExtractImageScansController { @Operation(summary = "Extract image scans from an input file", description = "This endpoint extracts image scans from a given file based on certain parameters. Users can specify angle threshold, tolerance, minimum area, minimum contour area, and border size. Input:PDF Output:IMAGE/ZIP Type:SIMO") public ResponseEntity extractImageScans( - @RequestPart(required = true, value = "fileInput") - @Parameter(description = "The input file containing image scans") - MultipartFile inputFile, - @RequestParam(name = "angle_threshold", defaultValue = "5") - @Parameter(description = "The angle threshold for the image scan extraction", example = "5") - int angleThreshold, - @RequestParam(name = "tolerance", defaultValue = "20") - @Parameter(description = "The tolerance for the image scan extraction", example = "20") - int tolerance, - @RequestParam(name = "min_area", defaultValue = "8000") - @Parameter(description = "The minimum area for the image scan extraction", example = "8000") - int minArea, - @RequestParam(name = "min_contour_area", defaultValue = "500") - @Parameter(description = "The minimum contour area for the image scan extraction", example = "500") - int minContourArea, - @RequestParam(name = "border_size", defaultValue = "1") - @Parameter(description = "The border size for the image scan extraction", example = "1") - int borderSize) throws IOException, InterruptedException { - - String fileName = inputFile.getOriginalFilename(); + @RequestBody( + description = "Form data containing file and extraction parameters", + required = true, + content = @Content( + mediaType = "multipart/form-data", + schema = @Schema(implementation = MyForm.class) // This should represent your form's structure + ) + ) + MyForm form) throws IOException, InterruptedException { + String fileName = form.getFileInput().getOriginalFilename(); String extension = fileName.substring(fileName.lastIndexOf(".") + 1); List images = new ArrayList<>(); @@ -73,7 +65,7 @@ public class ExtractImageScansController { // Check if input file is a PDF if (extension.equalsIgnoreCase("pdf")) { // Load PDF document - try (PDDocument document = PDDocument.load(new ByteArrayInputStream(inputFile.getBytes()))) { + try (PDDocument document = PDDocument.load(new ByteArrayInputStream(form.getFileInput().getBytes()))) { PDFRenderer pdfRenderer = new PDFRenderer(document); int pageCount = document.getNumberOfPages(); images = new ArrayList<>(); @@ -93,7 +85,7 @@ public class ExtractImageScansController { } } else { Path tempInputFile = Files.createTempFile("input_", "." + extension); - Files.copy(inputFile.getInputStream(), tempInputFile, StandardCopyOption.REPLACE_EXISTING); + Files.copy(form.getFileInput().getInputStream(), tempInputFile, StandardCopyOption.REPLACE_EXISTING); // Add input file path to images list images.add(tempInputFile.toString()); } @@ -109,11 +101,11 @@ public class ExtractImageScansController { "./scripts/split_photos.py", images.get(i), tempDir.toString(), - "--angle_threshold", String.valueOf(angleThreshold), - "--tolerance", String.valueOf(tolerance), - "--min_area", String.valueOf(minArea), - "--min_contour_area", String.valueOf(minContourArea), - "--border_size", String.valueOf(borderSize) + "--angle_threshold", String.valueOf(form.getAngleThreshold()), + "--tolerance", String.valueOf(form.getTolerance()), + "--min_area", String.valueOf(form.getMinArea()), + "--min_contour_area", String.valueOf(form.getMinContourArea()), + "--border_size", String.valueOf(form.getBorderSize()) )); diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java b/src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java new file mode 100644 index 00000000..1938493a --- /dev/null +++ b/src/main/java/stirling/software/SPDF/controller/api/other/MyForm.java @@ -0,0 +1,27 @@ +package stirling.software.SPDF.controller.api.other; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class MyForm { + @Schema(description = "The input file containing image scans", required = true) + private MultipartFile fileInput; + + @Schema(description = "The angle threshold for the image scan extraction", defaultValue = "5", example = "5") + private int angleThreshold; + + @Schema(description = "The tolerance for the image scan extraction", defaultValue = "20", example = "20") + private int tolerance; + + @Schema(description = "The minimum area for the image scan extraction", defaultValue = "8000", example = "8000") + private int minArea; + + @Schema(description = "The minimum contour area for the image scan extraction", defaultValue = "500", example = "500") + private int minContourArea; + + @Schema(description = "The border size for the image scan extraction", defaultValue = "1", example = "1") + private int borderSize; +} diff --git a/src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java b/src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java index aaaf22b4..6392be96 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java @@ -69,7 +69,7 @@ public class CertSignController { @PostMapping(consumes = "multipart/form-data", value = "/cert-sign") @Operation(summary = "Sign PDF with a Digital Certificate", description = "This endpoint accepts a PDF file, a digital certificate and related information to sign the PDF. It then returns the digitally signed PDF file. Input:PDF Output:PDF Type:MF-SISO") public ResponseEntity signPDF2( - @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to be signed") MultipartFile pdf, + @RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file") MultipartFile pdf, @RequestParam(value = "certType", required = false) @Parameter(description = "The type of the digital certificate", schema = @Schema(allowableValues = { "PKCS12", "PEM" })) String certType, diff --git a/src/main/java/stirling/software/SPDF/model/SortTypes.java b/src/main/java/stirling/software/SPDF/model/SortTypes.java new file mode 100644 index 00000000..21181cfa --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/SortTypes.java @@ -0,0 +1,4 @@ +package stirling.software.SPDF.model; +public enum SortTypes { + REVERSE_ORDER, DUPLEX_SORT, BOOKLET_SORT, SIDE_STITCH_BOOKLET_SORT, ODD_EVEN_SPLIT, REMOVE_FIRST, REMOVE_LAST, REMOVE_FIRST_AND_LAST, +} \ No newline at end of file diff --git a/src/main/java/stirling/software/SPDF/model/api/GeneralFile.java b/src/main/java/stirling/software/SPDF/model/api/GeneralFile.java new file mode 100644 index 00000000..84710585 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/GeneralFile.java @@ -0,0 +1,13 @@ +package stirling.software.SPDF.model.api; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class GeneralFile { + + @Schema(description = "The input file") + private MultipartFile fileInput; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/ImageFile.java b/src/main/java/stirling/software/SPDF/model/api/ImageFile.java new file mode 100644 index 00000000..8c4c0cff --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/ImageFile.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class ImageFile { + @Schema(description = "The input image file") + private MultipartFile fileInput; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/MultiplePDFFiles.java b/src/main/java/stirling/software/SPDF/model/api/MultiplePDFFiles.java new file mode 100644 index 00000000..17bec404 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/MultiplePDFFiles.java @@ -0,0 +1,11 @@ +package stirling.software.SPDF.model.api; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +@Data +public class MultiplePDFFiles { + @Schema(description = "The input PDF files", type = "array", format = "binary") + private MultipartFile[] fileInput; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/PDFFile.java b/src/main/java/stirling/software/SPDF/model/api/PDFFile.java new file mode 100644 index 00000000..0b304747 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/PDFFile.java @@ -0,0 +1,11 @@ +package stirling.software.SPDF.model.api; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +@Data +public class PDFFile { + @Schema(description = "The input PDF file") + private MultipartFile fileInput; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/PDFWithPageNums.java b/src/main/java/stirling/software/SPDF/model/api/PDFWithPageNums.java new file mode 100644 index 00000000..4de315de --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/PDFWithPageNums.java @@ -0,0 +1,36 @@ +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 PDFWithPageNums extends PDFFile { + + @Schema(description = "The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a constant (e.g., '2n+1', '3n', '6n-5')\"") + private String pageNumbers; + + + public List getPageNumbersList(){ + int pageCount = 0; + try { + pageCount = PDDocument.load(getFileInput().getInputStream()).getNumberOfPages(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return GeneralUtils.parsePageString(pageNumbers, pageCount); + + } + public List getPageNumbersList(PDDocument doc){ + int pageCount = 0; + pageCount = doc.getNumberOfPages(); + return GeneralUtils.parsePageString(pageNumbers, pageCount); + + } +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java new file mode 100644 index 00000000..34e36379 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java @@ -0,0 +1,22 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class ConvertToImageRequest extends PDFFile { + + @Schema(description = "The output image format", allowableValues = {"png", "jpeg", "jpg", "gif"}) + private String imageFormat; + + @Schema(description = "Choose between a single image containing all pages or separate images for each page", allowableValues = {"single", "multiple"}) + private String singleOrMultiple; + + @Schema(description = "The color type of the output image(s)", allowableValues = {"color", "greyscale", "blackwhite"}) + private String colorType; + + @Schema(description = "The DPI (dots per inch) for the output image(s)") + private String dpi; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToPdfRequest.java new file mode 100644 index 00000000..90325ed6 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToPdfRequest.java @@ -0,0 +1,21 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +@Data +public class ConvertToPdfRequest { + + @Schema(description = "The input images to be converted to a PDF file") + private MultipartFile[] fileInput; + + @Schema(description = "Whether to stretch the images to fit the PDF page or maintain the aspect ratio", example = "false") + private boolean stretchToFit; + + @Schema(description = "The color type of the output image(s)", allowableValues = {"color", "greyscale", "blackwhite"}) + private String colorType; + + @Schema(description = "Whether to automatically rotate the images to better fit the PDF page", example = "true") + private boolean autoRotate; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPresentationRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPresentationRequest.java new file mode 100644 index 00000000..f1bf7a9d --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPresentationRequest.java @@ -0,0 +1,13 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class PdfToPresentationRequest extends PDFFile { + + @Schema(description = "The output Presentation format", allowableValues = {"ppt", "pptx", "odp"}) + private String outputFormat; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/PdfToTextOrRTFRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToTextOrRTFRequest.java new file mode 100644 index 00000000..8093cd45 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToTextOrRTFRequest.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class PdfToTextOrRTFRequest extends PDFFile { + + @Schema(description = "The output Text or RTF format", allowableValues = {"rtf", "txt:Text"}) + private String outputFormat; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/PdfToWordRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToWordRequest.java new file mode 100644 index 00000000..de5a7c4e --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToWordRequest.java @@ -0,0 +1,12 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class PdfToWordRequest extends PDFFile { + + @Schema(description = "The output Word document format", allowableValues = {"doc", "docx", "odt"}) + private String outputFormat; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java new file mode 100644 index 00000000..7d4e69ed --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java @@ -0,0 +1,11 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class UrlToPdfRequest { + + @Schema(description = "The input URL to be converted to a PDF file", required = true) + private String urlInput; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/general/CropPdfForm.java b/src/main/java/stirling/software/SPDF/model/api/general/CropPdfForm.java new file mode 100644 index 00000000..52c0f269 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/CropPdfForm.java @@ -0,0 +1,26 @@ +package stirling.software.SPDF.model.api.general; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +import org.springframework.web.multipart.MultipartFile; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + +@Data +public class CropPdfForm extends PDFFile { + + + @Schema(description = "The x-coordinate of the top-left corner of the crop area", type = "number") + private float x; + + @Schema(description = "The y-coordinate of the top-left corner of the crop area", type = "number") + private float y; + + @Schema(description = "The width of the crop area", type = "number") + private float width; + + @Schema(description = "The height of the crop area", type = "number") + private float height; +} + diff --git a/src/main/java/stirling/software/SPDF/model/api/general/MergeMultiplePagesRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/MergeMultiplePagesRequest.java new file mode 100644 index 00000000..6752b1b7 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/MergeMultiplePagesRequest.java @@ -0,0 +1,13 @@ +package stirling.software.SPDF.model.api.general; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class MergeMultiplePagesRequest extends PDFFile { + + @Schema(description = "The number of pages to fit onto a single sheet in the output PDF.", + type = "integer", allowableValues = {"2", "3", "4", "9", "16"}) + private int pagesPerSheet; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/general/MergePdfsRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/MergePdfsRequest.java new file mode 100644 index 00000000..4e1ed397 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/MergePdfsRequest.java @@ -0,0 +1,20 @@ +package stirling.software.SPDF.model.api.general; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import stirling.software.SPDF.model.api.MultiplePDFFiles; + +@Data +public class MergePdfsRequest extends MultiplePDFFiles { + + @Schema(description = "The type of sorting to be applied on the input files before merging.", + allowableValues = { + "orderProvided", + "byFileName", + "byDateModified", + "byDateCreated", + "byPDFTitle" + }, + defaultValue = "orderProvided") + private String sortType; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/general/RearrangePagesRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/RearrangePagesRequest.java new file mode 100644 index 00000000..4e054343 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/RearrangePagesRequest.java @@ -0,0 +1,23 @@ +package stirling.software.SPDF.model.api.general; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; +import stirling.software.SPDF.model.api.PDFFile; +import stirling.software.SPDF.model.api.PDFWithPageNums; +import stirling.software.SPDF.model.SortTypes; +@Data +public class RearrangePagesRequest extends PDFWithPageNums { + + @Schema(implementation = SortTypes.class, description = "The custom mode for page rearrangement. Valid values are:\n" + + "REVERSE_ORDER: Reverses the order of all pages.\n" + + "DUPLEX_SORT: Sorts pages as if all fronts were scanned then all backs in reverse (1, n, 2, n-1, ...). " + + "BOOKLET_SORT: Arranges pages for booklet printing (last, first, second, second last, ...).\n" + + "ODD_EVEN_SPLIT: Splits and arranges pages into odd and even numbered pages.\n" + + "REMOVE_FIRST: Removes the first page.\n" + "REMOVE_LAST: Removes the last page.\n" + + "REMOVE_FIRST_AND_LAST: Removes both the first and the last pages.\n") + private String customMode; + + + +} diff --git a/src/main/java/stirling/software/SPDF/model/api/general/RotatePDFRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/RotatePDFRequest.java new file mode 100644 index 00000000..58d268a8 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/RotatePDFRequest.java @@ -0,0 +1,13 @@ +package stirling.software.SPDF.model.api.general; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class RotatePDFRequest extends PDFFile { + + @Schema(description = "The angle by which to rotate the PDF file. This should be a multiple of 90.", example = "90") + private Integer angle; +} diff --git a/src/main/java/stirling/software/SPDF/model/api/general/ScalePagesRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/ScalePagesRequest.java new file mode 100644 index 00000000..3411e1d2 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/general/ScalePagesRequest.java @@ -0,0 +1,20 @@ +package stirling.software.SPDF.model.api.general; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +public class ScalePagesRequest extends PDFFile { + + @Schema(description = "The scale of pages in the output PDF. Acceptable values are A0-A10, B0-B9, LETTER, TABLOID, LEDGER, LEGAL, EXECUTIVE.", + allowableValues = { + "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "B0", "B1", "B2", "B3", "B4", + "B5", "B6", "B7", "B8", "B9", "LETTER", "TABLOID", "LEDGER", "LEGAL", "EXECUTIVE" + }) + private String targetPDRectangle; + + @Schema(description = "The scale of the content on the pages of the output PDF. Acceptable values are floats.") + private float scaleFactor; +} diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index 34ee9c35..b4377039 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -75,6 +75,9 @@ public class GeneralUtils { return null; } + public static List parsePageString(String pageOrder, int totalPages) { + return parsePageList(pageOrder.split(","), 100); + } public static List parsePageList(String[] pageOrderArr, int totalPages) { List newPageOrder = new ArrayList<>();