diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..dce948a4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,33 @@ +pipeline { + agent any + stages { + stage('Build') { + steps { + sh 'chmod 755 gradlew' + sh './gradlew build' + } + } + stage('Docker Build') { + steps { + script { + def appVersion = sh(returnStdout: true, script: './gradlew printVersion -q').trim() + def image = "frooodle/s-pdf:$appVersion" + sh "docker build -t $image ." + } + } + } + stage('Docker Push') { + steps { + script { + def appVersion = sh(returnStdout: true, script: './gradlew printVersion -q').trim() + def image = "frooodle/s-pdf:$appVersion" + withCredentials([string(credentialsId: 'docker_hub_access_token', variable: 'DOCKER_HUB_ACCESS_TOKEN')]) { + sh "docker login --username frooodle --password $DOCKER_HUB_ACCESS_TOKEN" + sh "docker push $image" + } + } + } + + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index fc1b7552..3f5fcec9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# Stirling-PDF (Made in 1 day with 100% ChatGPT, Even this readme!) +# Stirling-PDF This is a locally hosted web application that allows you to perform various operations on PDF files, such as splitting and adding images. -I will support and fix/add things to this if there is a demand [Discord](https://discord.gg/Cn8pWhQRxZ) - ## Features - Split PDFs into multiple files at specified page numbers or extract all pages as individual files. @@ -33,8 +31,6 @@ Prerequisites ### Docker -https://hub.docker.com/r/frooodle/s-pdf - docker pull frooodle/s-pdf docker run -p 8080:8080 frooodle/s-pdf @@ -45,4 +41,4 @@ docker run -p 8080:8080 frooodle/s-pdf 2. Use the application by following the instructions on the website. ## Note -The application is currently not thread-safe +The application is currently not thread-safe \ No newline at end of file diff --git a/build.gradle b/build.gradle index b290c978..50c314f1 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.apache.pdfbox:pdfbox:2.0.27' - implementation 'log4j:log4j' + implementation 'org.apache.logging.log4j:log4j-core:2.19.0' } tasks.named('test') { diff --git a/src/main/java/stirling/software/SPDF/controller/FromPDFController.java b/src/main/java/stirling/software/SPDF/controller/FromPDFController.java index cfd2d54b..7f0ede1c 100644 --- a/src/main/java/stirling/software/SPDF/controller/FromPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/FromPDFController.java @@ -4,6 +4,10 @@ import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -23,10 +27,26 @@ public class FromPDFController { } @PostMapping("/convert-from-pdf") - public byte[] convertToImage(@RequestParam("fileInput") MultipartFile file, + public ResponseEntity convertToImage(@RequestParam("fileInput") MultipartFile file, @RequestParam("imageFormat") String imageFormat) throws IOException { byte[] pdfBytes = file.getBytes(); - return PdfUtils.convertFromPdf(pdfBytes, imageFormat); + //returns bytes for image + byte[] result = PdfUtils.convertFromPdf(pdfBytes, imageFormat.toLowerCase()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.parseMediaType(getMediaType(imageFormat))); + headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); + ResponseEntity response = new ResponseEntity<>(result, headers, HttpStatus.OK); + return response; } + private String getMediaType(String imageFormat) { + if(imageFormat.equalsIgnoreCase("PNG")) + return "image/png"; + else if(imageFormat.equalsIgnoreCase("JPEG")) + return "image/jpeg"; + else if(imageFormat.equalsIgnoreCase("GIF")) + return "image/gif"; + else + return "application/octet-stream"; + } } diff --git a/src/main/resources/templates/common.html b/src/main/resources/templates/common.html index 22d8e096..cd793253 100644 --- a/src/main/resources/templates/common.html +++ b/src/main/resources/templates/common.html @@ -1,77 +1,95 @@ - - - - - - - - - - - - - -
-
- - -
- + + + + + + + + + + + + + +
+
+ + + + + +
\ No newline at end of file diff --git a/src/main/resources/templates/convert-from-pdf.html b/src/main/resources/templates/convert-from-pdf.html index 47f0e946..c1fffd73 100644 --- a/src/main/resources/templates/convert-from-pdf.html +++ b/src/main/resources/templates/convert-from-pdf.html @@ -15,7 +15,7 @@

PDF to img

+ th:action="@{/convert-from-pdf}">
+
\ No newline at end of file diff --git a/src/main/resources/templates/merge-pdfs.html b/src/main/resources/templates/merge-pdfs.html index eea2e9f2..c2ee73a2 100644 --- a/src/main/resources/templates/merge-pdfs.html +++ b/src/main/resources/templates/merge-pdfs.html @@ -4,33 +4,16 @@ S-PDF MergePDFs -


-
+
-
+

Merge multiple PDFs (2+)

diff --git a/src/main/resources/templates/split-pdfs.html b/src/main/resources/templates/split-pdfs.html index 40c2ab53..768b3332 100644 --- a/src/main/resources/templates/split-pdfs.html +++ b/src/main/resources/templates/split-pdfs.html @@ -15,7 +15,7 @@

Split PDF

The numbers you select are the page number you wish to do a split on

-

As such selecting 1,3,7-8 would split a 12 page document into +

As such selecting 1,3,7-8 would split a 10 page document into 6 separate PDFS with:

Document #1: Page 1

Document #2: Page 2 and 3