From 5dee64ab7bf7b06a2ad34c6def8cc24692b020eb Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Sun, 26 May 2024 15:31:34 +0100 Subject: [PATCH] changes --- .../SPDF/config/ConfigInitializer.java | 21 +++++++------------ .../converters/ConvertImgPDFController.java | 7 +++---- .../api/misc/BlankPageController.java | 2 +- .../SPDF/model/ApplicationProperties.java | 3 --- .../software/SPDF/utils/PDFToFile.java | 15 +++++++++++-- src/main/resources/messages_fr_FR.properties | 2 +- src/main/resources/settings.yml.template | 2 +- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java b/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java index e8433588..8621dd62 100644 --- a/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java +++ b/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java @@ -8,11 +8,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; @@ -85,8 +81,8 @@ public class ConfigInitializer resultLines.add(""); } } - - // Write the result to the user settings file + + // Write the result to the user settings file Files.write(userPath, resultLines); } @@ -95,11 +91,10 @@ public class ConfigInitializer Files.createFile(customSettingsPath); } } - - - - //TODO check parent value instead of just indent lines for duplicate keys (like enabled etc) - private static void addLine(List resultLines, List userLines, String templateLine, String key) { + + // TODO check parent value instead of just indent lines for duplicate keys (like enabled etc) + private static void addLine( + List resultLines, List userLines, String templateLine, String key) { boolean added = false; int templateIndentationLevel = getIndentationLevel(templateLine); for (String settingsLine : userLines) { @@ -116,13 +111,13 @@ public class ConfigInitializer if (!added) { resultLines.add(templateLine); } - } + } private static int getIndentationLevel(String line) { int indentationLevel = 0; String trimmedLine = line.trim(); if (trimmedLine.startsWith("#")) { - line = trimmedLine.substring(1); + line = trimmedLine.substring(1); } for (char c : line.toCharArray()) { if (c == ' ') { 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 3f880a80..25c37aad 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 @@ -56,7 +56,7 @@ public class ConvertImgPDFController { String filename = Filenames.toSimpleFileName(file.getOriginalFilename()) .replaceFirst("[.][^.]+$", ""); - + result = PdfUtils.convertFromPdf( pdfBytes, @@ -65,10 +65,9 @@ public class ConvertImgPDFController { singleImage, Integer.valueOf(dpi), filename); - - if(result == null || result.length == 0) { - logger.error("resultant bytes for {} is null, error converting ", filename); + if (result == null || result.length == 0) { + logger.error("resultant bytes for {} is null, error converting ", filename); } if (singleImage) { String docName = filename + "." + imageFormat; diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java index eaac72a0..73dab071 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/BlankPageController.java @@ -67,7 +67,7 @@ public class BlankPageController { String pageText = textStripper.getText(document); boolean hasText = !pageText.trim().isEmpty(); - Boolean blank = false; + Boolean blank = true; if (hasText) { logger.info("page " + pageIndex + " has text, not blank"); blank = false; diff --git a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java index ae96d07b..b926b845 100644 --- a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java +++ b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java @@ -381,9 +381,6 @@ public class ApplicationProperties { this.googlevisibility = googlevisibility; } - - - @Override public String toString() { return "System [defaultLocale=" diff --git a/src/main/java/stirling/software/SPDF/utils/PDFToFile.java b/src/main/java/stirling/software/SPDF/utils/PDFToFile.java index e52344bf..38579aa8 100644 --- a/src/main/java/stirling/software/SPDF/utils/PDFToFile.java +++ b/src/main/java/stirling/software/SPDF/utils/PDFToFile.java @@ -34,7 +34,10 @@ public class PDFToFile { // Get the original PDF file name without the extension String originalPdfFileName = Filenames.toSimpleFileName(inputFile.getOriginalFilename()); - String pdfBaseName = originalPdfFileName.substring(0, originalPdfFileName.lastIndexOf('.')); + String pdfBaseName = originalPdfFileName; + if (originalPdfFileName.contains(".")) { + pdfBaseName = originalPdfFileName.substring(0, originalPdfFileName.lastIndexOf('.')); + } Path tempInputFile = null; Path tempOutputDir = null; @@ -100,8 +103,15 @@ public class PDFToFile { // Get the original PDF file name without the extension String originalPdfFileName = Filenames.toSimpleFileName(inputFile.getOriginalFilename()); - String pdfBaseName = originalPdfFileName.substring(0, originalPdfFileName.lastIndexOf('.')); + if (originalPdfFileName == null || "".equals(originalPdfFileName.trim())) { + originalPdfFileName = "output.pdf"; + } + // Assume file is pdf if no extension + String pdfBaseName = originalPdfFileName; + if (originalPdfFileName.contains(".")) { + pdfBaseName = originalPdfFileName.substring(0, originalPdfFileName.lastIndexOf('.')); + } // Validate output format List allowedFormats = Arrays.asList("doc", "docx", "odt", "ppt", "pptx", "odp", "rtf", "xml", "txt:Text"); @@ -173,6 +183,7 @@ public class PDFToFile { if (tempInputFile != null) Files.delete(tempInputFile); if (tempOutputDir != null) FileUtils.deleteDirectory(tempOutputDir.toFile()); } + System.out.println("fileBytes=" + fileBytes.length); return WebResponseUtils.bytesToWebResponse( fileBytes, fileName, MediaType.APPLICATION_OCTET_STREAM); } diff --git a/src/main/resources/messages_fr_FR.properties b/src/main/resources/messages_fr_FR.properties index 26afdb0e..b9a700ca 100644 --- a/src/main/resources/messages_fr_FR.properties +++ b/src/main/resources/messages_fr_FR.properties @@ -17,7 +17,7 @@ true=Vrai false=Faux unknown=Inconnu save=Enregistrer -saveToBrowser=Enregistrer dans le navigateur +saveToBrowser=Enregistrer dans le navigateur close=Fermer filesSelected=fichiers sélectionnés noFavourites=Aucun favori ajouté diff --git a/src/main/resources/settings.yml.template b/src/main/resources/settings.yml.template index c2a201ef..0c1c887b 100644 --- a/src/main/resources/settings.yml.template +++ b/src/main/resources/settings.yml.template @@ -24,7 +24,7 @@ system: defaultLocale: 'en-US' # Set the default language (e.g. 'de-DE', 'fr-FR', etc) googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow enableAlphaFunctionality: false # Set to enable functionality which might need more testing before it fully goes live (This feature might make no changes) - showUpdate: true # see when a new update is available + showUpdate: false # see when a new update is available showUpdateOnlyAdmin: false # Only admins can see when a new update is available, depending on showUpdate it must be set to 'true' customHTMLFiles: false # enable to have files placed in /customFiles/templates override the existing template html files