From b702f5772d2b9574c66cf0995ffc4b1dd229e682 Mon Sep 17 00:00:00 2001 From: phfuh <136272363+phfuh@users.noreply.github.com> Date: Sun, 21 Apr 2024 09:44:05 +0200 Subject: [PATCH] Add selection for PDF/A output format (#1095) * Create PdfToPdfARequest.java * Change class, add output format * Add input field for output format * Change output format selection order --- .../api/converters/ConvertPDFToPDFA.java | 7 ++++--- .../model/api/converters/PdfToPdfARequest.java | 17 +++++++++++++++++ .../templates/convert/pdf-to-pdfa.html | 9 ++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/main/java/stirling/software/SPDF/model/api/converters/PdfToPdfARequest.java 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 41498413..119e0902 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 @@ -16,7 +16,7 @@ import io.github.pixee.security.Filenames; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import stirling.software.SPDF.model.api.PDFFile; +import stirling.software.SPDF.model.api.converters.PdfToPdfARequest; import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.WebResponseUtils; @@ -31,8 +31,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(@ModelAttribute PDFFile request) throws Exception { + public ResponseEntity pdfToPdfA(@ModelAttribute PdfToPdfARequest request) throws Exception { MultipartFile inputFile = request.getFileInput(); + String outputFormat = request.getOutputFormat(); // Save the uploaded file to a temporary location Path tempInputFile = Files.createTempFile("input_", ".pdf"); @@ -47,7 +48,7 @@ public class ConvertPDFToPDFA { command.add("--skip-text"); command.add("--tesseract-timeout=0"); command.add("--output-type"); - command.add("pdfa"); + command.add(outputFormat.toString()); command.add(tempInputFile.toString()); command.add(tempOutputFile.toString()); diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPdfARequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPdfARequest.java new file mode 100644 index 00000000..59535314 --- /dev/null +++ b/src/main/java/stirling/software/SPDF/model/api/converters/PdfToPdfARequest.java @@ -0,0 +1,17 @@ +package stirling.software.SPDF.model.api.converters; + +import io.swagger.v3.oas.annotations.media.Schema; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import stirling.software.SPDF.model.api.PDFFile; + +@Data +@EqualsAndHashCode(callSuper = true) +public class PdfToPdfARequest extends PDFFile { + + @Schema( + description = "The output PDF/A type", + allowableValues = {"pdfa", "pdfa-1"}) + private String outputFormat; +} diff --git a/src/main/resources/templates/convert/pdf-to-pdfa.html b/src/main/resources/templates/convert/pdf-to-pdfa.html index 6494cf9c..6f558a1e 100644 --- a/src/main/resources/templates/convert/pdf-to-pdfa.html +++ b/src/main/resources/templates/convert/pdf-to-pdfa.html @@ -17,6 +17,13 @@

+
+ + +

@@ -28,4 +35,4 @@ - \ No newline at end of file +