From 28faf3888c5a23d4a02dd6282850ddf2c2b973de Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Mon, 8 May 2023 22:55:01 +0100 Subject: [PATCH] init home for toher featues --- README.md | 12 +- ...t-blank-pages.sh => detect-blank-pages.py} | 0 .../api/other/BlankPageController.java | 10 +- .../controller/web/GeneralWebController.java | 4 +- src/main/resources/messages_en_GB.properties | 6 + .../resources/static/images/blank-file.svg | 3 + src/main/resources/static/images/scales.svg | 94 +++++++++++ src/main/resources/templates/home.html | 4 +- .../resources/templates/other/compare.html | 147 +++++++++--------- 9 files changed, 197 insertions(+), 83 deletions(-) rename scripts/{detect-blank-pages.sh => detect-blank-pages.py} (100%) create mode 100644 src/main/resources/static/images/blank-file.svg create mode 100644 src/main/resources/static/images/scales.svg diff --git a/README.md b/README.md index 9c7d3e0c..a80ddca0 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Feel free to request any features or bug fixes either in github issues or our [D - Add/Generate signatures - Flatten PDFs - Repair PDFs +- Detect and remove blank pages +- Compare 2 PDFs and show differences in text - Add images to PDFs - Rotating PDFs in 90 degree increments. - Compressing PDFs to decrease their filesize. (Using OCRMyPDF) @@ -77,10 +79,12 @@ docker run -d \ frooodle/s-pdf - Can also add these for customisation + Can also add these for customisation but are not required -e APP_HOME_NAME="Stirling PDF" \ -e APP_HOME_DESCRIPTION="Your locally hosted one-stop-shop for all your PDF needs." \ -e APP_NAVBAR_NAME="Stirling PDF" \ + -e ALLOW_GOOGLE_VISABILITY="true" \ + -e APP_LOCALE="en_GB" \ ``` Docker Compose ``` @@ -94,9 +98,11 @@ services: - /location/of/trainingData:/usr/share/tesseract-ocr/4.00/tessdata #Required for extra OCR languages # - /location/of/extraConfigs:/configs # environment: +# APP_LOCALE: en_GB # APP_HOME_NAME: Stirling PDF # APP_HOME_DESCRIPTION: Your locally hosted one-stop-shop for all your PDF needs. # APP_NAVBAR_NAME: Stirling PDF +# ALLOW_GOOGLE_VISABILITY: true ``` @@ -122,7 +128,9 @@ Stirling PDF allows easy customization of the visible application name. Simply use environment variables APP_HOME_NAME, APP_HOME_DESCRIPTION and APP_NAVBAR_NAME with Docker or Java. If running Java directly, you can also pass these as properties using -D arguments. -Using the same method you can also change the default language by providing APP_LOCALE with values like de-DE fr-FR or ar-AR to select your default language (Will always default to English on invalid locale) +Using the same method you can also change +- The default language by providing APP_LOCALE with values like de-DE fr-FR or ar-AR to select your default language (Will always default to English on invalid locale) +- Enable/Disable search engine visablility with ALLOW_GOOGLE_VISABILITY with true / false values. Default disable visability. ## API For those wanting to use Stirling-PDFs backend API to link with their own custom scripting to edit PDFs you can view all existing API documentation diff --git a/scripts/detect-blank-pages.sh b/scripts/detect-blank-pages.py similarity index 100% rename from scripts/detect-blank-pages.sh rename to scripts/detect-blank-pages.py diff --git a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java b/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java index b8cb651b..bf29c774 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/other/BlankPageController.java @@ -30,8 +30,9 @@ public class BlankPageController { @PostMapping(consumes = "multipart/form-data", value = "/remove-blanks") public ResponseEntity removeBlankPages(@RequestPart(required = true, value = "fileInput") MultipartFile inputFile) throws IOException, InterruptedException { + PDDocument document = null; try { - PDDocument document = PDDocument.load(inputFile.getInputStream()); + document = PDDocument.load(inputFile.getInputStream()); PDPageTree pages = document.getDocumentCatalog().getPages(); PDFTextStripper textStripper = new PDFTextStripper(); @@ -67,7 +68,7 @@ public class BlankPageController { BufferedImage image = pdfRenderer.renderImageWithDPI(i - 1, 300); ImageIO.write(image, "png", tempFile.toFile()); - List command = new ArrayList<>(Arrays.asList("python3", "./scripts/detect-blank-pages.py", tempFile.toString())); + List command = new ArrayList<>(Arrays.asList("python3", System.getProperty("user.dir") + "scripts/detect-blank-pages.py", tempFile.toString())); // Run CLI command int returnCode = ProcessExecutor.getInstance(ProcessExecutor.Processes.PYTHON_OPENCV).runCommandWithOutputHandling(command); @@ -81,12 +82,15 @@ public class BlankPageController { } - document.close(); + return PdfUtils.pdfDocToWebResponse(outputDocument, inputFile.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_blanksRemoved.pdf"); } catch (IOException e) { e.printStackTrace(); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } finally { + if(document != null) + document.close(); } } diff --git a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java index c5184abe..aca36980 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java @@ -84,9 +84,9 @@ public class GeneralWebController { if (allowGoogleVisibility == null) allowGoogleVisibility = System.getenv("ALLOW_GOOGLE_VISABILITY"); if (allowGoogleVisibility == null) - allowGoogleVisibility = "true"; + allowGoogleVisibility = "false"; if (Boolean.parseBoolean(allowGoogleVisibility)) { - return "User-agent: Googlebot\nAllow: /\n\nUser-agent: *\nDisallow: /"; + return "User-agent: Googlebot\nAllow: /\n\nUser-agent: *\nAllow: /"; } else { return "User-agent: Googlebot\nDisallow: /\n\nUser-agent: *\nDisallow: /"; } diff --git a/src/main/resources/messages_en_GB.properties b/src/main/resources/messages_en_GB.properties index b7030811..aca3d733 100644 --- a/src/main/resources/messages_en_GB.properties +++ b/src/main/resources/messages_en_GB.properties @@ -117,6 +117,12 @@ home.flatten.desc=Remove all interactive elements and forms from a PDF home.repair.title=Repair home.repair.desc=Tries to repair a corrupt/broken PDF +home.removeBlanks.title=Remove Blank pages +home.removeBlanks.desc=Detects and removes blank pages from a document + +home.compare.title=Compare +home.compare.desc=Compares and shows the differences between 2 PDF Documents + downloadPdf=Download PDF text=Text font=Font diff --git a/src/main/resources/static/images/blank-file.svg b/src/main/resources/static/images/blank-file.svg new file mode 100644 index 00000000..3562fb2b --- /dev/null +++ b/src/main/resources/static/images/blank-file.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/main/resources/static/images/scales.svg b/src/main/resources/static/images/scales.svg new file mode 100644 index 00000000..61b9c381 --- /dev/null +++ b/src/main/resources/static/images/scales.svg @@ -0,0 +1,94 @@ + + + + + + + + +image/svg+xmlOpenclipartscales of justice2009-06-26T04:35:18https://openclipart.org/detail/26849/scales-of-justice-by-johnny_automaticjohnny_automaticjusticelawmeasurementscalessilhouetteweight diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index e143f28b..b4f38f6f 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -112,8 +112,8 @@ filter: invert(0.2) sepia(2) saturate(50) hue-rotate(190deg);
-
-
+
+
diff --git a/src/main/resources/templates/other/compare.html b/src/main/resources/templates/other/compare.html index 591eb7ae..b59ee192 100644 --- a/src/main/resources/templates/other/compare.html +++ b/src/main/resources/templates/other/compare.html @@ -18,7 +18,25 @@
-
+
+
+

Document 1

+
+
+
+

Document 2

+
+
+
+ + + // Add space after each word + const space1 = document.createElement("span"); + const space2 = document.createElement("span"); + space1.textContent = " "; + space2.textContent = " "; + resultDiv1.appendChild(space1); + resultDiv2.appendChild(space2); + }); + return result; + }; + console.log('Differences:', differences); + displayDifferences(differences); + } +
- - - \ No newline at end of file