From e9f80d03ea38eebb3c3a3a2f5cafbd12f05df137 Mon Sep 17 00:00:00 2001 From: Reece Browne Date: Wed, 18 Dec 2024 00:16:01 +0000 Subject: [PATCH 1/3] Fix missing info in form data --- src/main/resources/static/js/downloader.js | 5 ++- .../static/js/pages/adjust-contrast.js | 2 +- .../templates/convert/img-to-pdf.html | 45 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index 57ae8c47b..e2a0364b7 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -412,8 +412,9 @@ const promises = chunk.map(async (file) => { let fileFormData = new FormData(); fileFormData.append('fileInput', file); - console.log(fileFormData); - // Add other form data + for (let [key, value] of fileFormData.entries()) { + console.log(key, value); + } // Add other form data for (let pair of formData.entries()) { fileFormData.append(pair[0], pair[1]); console.log(pair[0] + ', ' + pair[1]); diff --git a/src/main/resources/static/js/pages/adjust-contrast.js b/src/main/resources/static/js/pages/adjust-contrast.js index 792c06669..a9692d2bc 100644 --- a/src/main/resources/static/js/pages/adjust-contrast.js +++ b/src/main/resources/static/js/pages/adjust-contrast.js @@ -222,7 +222,7 @@ async function downloadPDF() { // Event listeners document.getElementById('fileInput-input').addEventListener('change', function (e) { - const fileInput = event.target; + const fileInput = e.target; fileInput.addEventListener('file-input-change', async (e) => { const {allFiles} = e.detail; if (allFiles && allFiles.length > 0) { diff --git a/src/main/resources/templates/convert/img-to-pdf.html b/src/main/resources/templates/convert/img-to-pdf.html index 758e83289..fa0fc74f2 100644 --- a/src/main/resources/templates/convert/img-to-pdf.html +++ b/src/main/resources/templates/convert/img-to-pdf.html @@ -17,7 +17,7 @@ image -
+
@@ -51,15 +51,18 @@
From 12d86049f6cd030ac8ff9f0e4df2564f17546e08 Mon Sep 17 00:00:00 2001 From: Reece Browne Date: Wed, 18 Dec 2024 00:30:06 +0000 Subject: [PATCH 2/3] Add default to convert image to pdf api --- .../api/converters/ConvertImgPDFController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 b5eec3923..3e4fa6ba0 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 @@ -210,7 +210,13 @@ public class ConvertImgPDFController { String fitOption = request.getFitOption(); String colorType = request.getColorType(); boolean autoRotate = request.isAutoRotate(); - + // Handle Null entries for formdata + if (colorType == null || colorType.isBlank()) { + colorType = "color"; + } + if (fitOption == null || fitOption.isEmpty()) { + fitOption = "fitDocumentToImage"; + } // Convert the file to PDF and get the resulting bytes byte[] bytes = PdfUtils.imageToPdf(file, fitOption, autoRotate, colorType, pdfDocumentFactory); From 9eed761346018c84f029abb5fa90029c8c14c6bf Mon Sep 17 00:00:00 2001 From: Reece Browne Date: Wed, 18 Dec 2024 00:36:04 +0000 Subject: [PATCH 3/3] Correct default fit --- .../SPDF/controller/api/converters/ConvertImgPDFController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3e4fa6ba0..cee8b962a 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 @@ -215,7 +215,7 @@ public class ConvertImgPDFController { colorType = "color"; } if (fitOption == null || fitOption.isEmpty()) { - fitOption = "fitDocumentToImage"; + fitOption = "fillPage"; } // Convert the file to PDF and get the resulting bytes byte[] bytes =