From 69c25cc5dfc47bba07bba2cccc74c71c2a57dab0 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:07:49 +0000 Subject: [PATCH] Delete src/main directory --- .../software/SPDF/SPdfApplication.java | 13 -- .../SPDF/controller/CompressController.java | 87 ----------- .../SPDF/controller/ConvertPDFController.java | 70 --------- .../controller/OverlayImageController.java | 49 ------ .../SPDF/controller/PdfController.java | 88 ----------- .../RearrangePagesPDFController.java | 108 ------------- .../SPDF/controller/RotationController.java | 74 --------- .../SPDF/controller/SplitPDFController.java | 142 ------------------ .../software/SPDF/utils/PdfUtils.java | 124 --------------- src/main/resources/application.properties | 11 -- src/main/resources/log4j.properties | 8 - src/main/resources/static/dark-mode.css | 23 --- src/main/resources/static/favicon.png | Bin 4356 -> 0 bytes src/main/resources/static/favicon.svg | 1 - src/main/resources/static/general.css | 5 - src/main/resources/templates/add-image.html | 51 ------- src/main/resources/templates/common.html | 95 ------------ .../resources/templates/compress-pdf.html | 43 ------ src/main/resources/templates/convert-pdf.html | 61 -------- src/main/resources/templates/footer.html | 11 -- src/main/resources/templates/home.html | 108 ------------- src/main/resources/templates/merge-pdfs.html | 106 ------------- src/main/resources/templates/navbar.html | 49 ------ .../resources/templates/pdf-organizer.html | 42 ------ src/main/resources/templates/rotate-pdf.html | 47 ------ src/main/resources/templates/split-pdfs.html | 49 ------ 26 files changed, 1465 deletions(-) delete mode 100644 src/main/java/stirling/software/SPDF/SPdfApplication.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/CompressController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/ConvertPDFController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/OverlayImageController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/PdfController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/RearrangePagesPDFController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/RotationController.java delete mode 100644 src/main/java/stirling/software/SPDF/controller/SplitPDFController.java delete mode 100644 src/main/java/stirling/software/SPDF/utils/PdfUtils.java delete mode 100644 src/main/resources/application.properties delete mode 100644 src/main/resources/log4j.properties delete mode 100644 src/main/resources/static/dark-mode.css delete mode 100644 src/main/resources/static/favicon.png delete mode 100644 src/main/resources/static/favicon.svg delete mode 100644 src/main/resources/static/general.css delete mode 100644 src/main/resources/templates/add-image.html delete mode 100644 src/main/resources/templates/common.html delete mode 100644 src/main/resources/templates/compress-pdf.html delete mode 100644 src/main/resources/templates/convert-pdf.html delete mode 100644 src/main/resources/templates/footer.html delete mode 100644 src/main/resources/templates/home.html delete mode 100644 src/main/resources/templates/merge-pdfs.html delete mode 100644 src/main/resources/templates/navbar.html delete mode 100644 src/main/resources/templates/pdf-organizer.html delete mode 100644 src/main/resources/templates/rotate-pdf.html delete mode 100644 src/main/resources/templates/split-pdfs.html diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java deleted file mode 100644 index b0f260ad8..000000000 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package stirling.software.SPDF; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SPdfApplication { - - public static void main(String[] args) { - SpringApplication.run(SPdfApplication.class, args); - } - -} diff --git a/src/main/java/stirling/software/SPDF/controller/CompressController.java b/src/main/java/stirling/software/SPDF/controller/CompressController.java deleted file mode 100644 index bffd19f07..000000000 --- a/src/main/java/stirling/software/SPDF/controller/CompressController.java +++ /dev/null @@ -1,87 +0,0 @@ -package stirling.software.SPDF.controller; - -import java.io.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.apache.pdfbox.pdmodel.PDDocument; -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.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import com.spire.pdf.PdfCompressionLevel; -import com.spire.pdf.PdfDocument; -import com.spire.pdf.PdfPageBase; -import com.spire.pdf.exporting.PdfImageInfo; -import com.spire.pdf.graphics.PdfBitmap; - -import stirling.software.SPDF.utils.PdfUtils; -//import com.spire.pdf.*; -@Controller -public class CompressController { - - private static final Logger logger = LoggerFactory.getLogger(CompressController.class); - - @GetMapping("/compress-pdf") - public String compressPdfForm(Model model) { - model.addAttribute("currentPage", "compress-pdf"); - return "compress-pdf"; - } - - @PostMapping("/compress-pdf") - public ResponseEntity compressPDF(@RequestParam("fileInput") MultipartFile pdfFile, - @RequestParam("imageCompressionLevel") String imageCompressionLevel) throws IOException { - - - //Load a sample PDF document - PdfDocument document = new PdfDocument(); - document.loadFromBytes(pdfFile.getBytes()); - - //Compress PDF - document.getFileInfo().setIncrementalUpdate(false); - document.setCompressionLevel(PdfCompressionLevel.Best); - - //compress PDF Images - for (int i = 0; i < document.getPages().getCount(); i++) { - - PdfPageBase page = document.getPages().get(i); - PdfImageInfo[] images = page.getImagesInfo(); - if (images != null && images.length > 0) - for (int j = 0; j < images.length; j++) { - PdfImageInfo image = images[j]; - PdfBitmap bp = new PdfBitmap(image.getImage()); - //bp.setPngDirectToJpeg(true); - bp.setQuality(Integer.valueOf(imageCompressionLevel)); - - page.replaceImage(j, bp); - - } - } - - // Save the rearranged PDF to a ByteArrayOutputStream - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - document.saveToStream(outputStream); - - // Close the original document - document.close(); - - // Prepare the response headers - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_PDF); - headers.setContentDispositionFormData("attachment", "compressed.pdf"); - headers.setContentLength(outputStream.size()); - - // Return the response with the PDF data and headers - return new ResponseEntity<>(outputStream.toByteArray(), headers, HttpStatus.OK); - } - -} diff --git a/src/main/java/stirling/software/SPDF/controller/ConvertPDFController.java b/src/main/java/stirling/software/SPDF/controller/ConvertPDFController.java deleted file mode 100644 index c37c5e8a1..000000000 --- a/src/main/java/stirling/software/SPDF/controller/ConvertPDFController.java +++ /dev/null @@ -1,70 +0,0 @@ -package stirling.software.SPDF.controller; - -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.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import stirling.software.SPDF.utils.PdfUtils; - -@Controller -public class ConvertPDFController { - - private static final Logger logger = LoggerFactory.getLogger(ConvertPDFController.class); - - @GetMapping("/convert-pdf") - public String convertToPdfForm(Model model) { - model.addAttribute("currentPage", "convert-pdf"); - return "convert-pdf"; - } - - @PostMapping("/convert-to-pdf") - public ResponseEntity convertToPdf(@RequestParam("fileInput") MultipartFile file) throws IOException { - // Convert the file to PDF and get the resulting bytes - byte[] bytes = PdfUtils.convertToPdf(file.getInputStream()); - logger.info("File {} successfully converted to pdf", file.getOriginalFilename()); - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_PDF); - String filename = "converted.pdf"; - headers.setContentDispositionFormData(filename, filename); - headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); - ResponseEntity response = new ResponseEntity<>(bytes, headers, HttpStatus.OK); - return response; - } - - @PostMapping("/convert-from-pdf") - public ResponseEntity convertToImage(@RequestParam("fileInput") MultipartFile file, - @RequestParam("imageFormat") String imageFormat) throws IOException { - byte[] pdfBytes = file.getBytes(); - //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") || imageFormat.equalsIgnoreCase("JPG")) - return "image/jpeg"; - else if(imageFormat.equalsIgnoreCase("GIF")) - return "image/gif"; - else - return "application/octet-stream"; - } - -} diff --git a/src/main/java/stirling/software/SPDF/controller/OverlayImageController.java b/src/main/java/stirling/software/SPDF/controller/OverlayImageController.java deleted file mode 100644 index f2a28469f..000000000 --- a/src/main/java/stirling/software/SPDF/controller/OverlayImageController.java +++ /dev/null @@ -1,49 +0,0 @@ -package stirling.software.SPDF.controller; - -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.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import stirling.software.SPDF.utils.PdfUtils; - -@Controller -public class OverlayImageController { - - private static final Logger logger = LoggerFactory.getLogger(OverlayImageController.class); - - @GetMapping("/add-image") - public String overlayImage(Model model) { - model.addAttribute("currentPage", "add-image"); - return "add-image"; - } - - @PostMapping("/add-image") - public ResponseEntity overlayImage(@RequestParam("fileInput") MultipartFile pdfFile, - @RequestParam("fileInput2") MultipartFile imageFile, @RequestParam("x") float x, - @RequestParam("y") float y) { - try { - byte[] pdfBytes = pdfFile.getBytes(); - byte[] imageBytes = imageFile.getBytes(); - byte[] result = PdfUtils.overlayImage(pdfBytes, imageBytes, x, y); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_PDF); - headers.setContentDispositionFormData("attachment", "overlayed.pdf"); - headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); - return new ResponseEntity<>(result, headers, HttpStatus.OK); - } catch (IOException e) { - logger.error("Failed to add image to PDF", e); - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } - } -} diff --git a/src/main/java/stirling/software/SPDF/controller/PdfController.java b/src/main/java/stirling/software/SPDF/controller/PdfController.java deleted file mode 100644 index e66fb9a50..000000000 --- a/src/main/java/stirling/software/SPDF/controller/PdfController.java +++ /dev/null @@ -1,88 +0,0 @@ -package stirling.software.SPDF.controller; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageTree; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.InputStreamResource; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -@Controller -public class PdfController { - - private static final Logger logger = LoggerFactory.getLogger(PdfController.class); - - @GetMapping("/") - public String root(Model model) { - return "redirect:/home"; - } - - @GetMapping("/merge-pdfs") - public String hello(Model model) { - model.addAttribute("currentPage", "merge-pdfs"); - return "merge-pdfs"; - } - - @GetMapping("/home") - public String home(Model model) { - model.addAttribute("currentPage", "home"); - return "home"; - } - - @PostMapping("/merge-pdfs") - public ResponseEntity mergePdfs(@RequestParam("fileInput") MultipartFile[] files) - throws IOException { - // Read the input PDF files into PDDocument objects - List documents = new ArrayList<>(); - - // Loop through the files array and read each file into a PDDocument - for (MultipartFile file : files) { - documents.add(PDDocument.load(file.getInputStream())); - } - - PDDocument mergedDoc = mergeDocuments(documents); - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - mergedDoc.save(byteArrayOutputStream); - mergedDoc.close(); - - // Create an InputStreamResource from the merged PDF - InputStreamResource resource = new InputStreamResource( - new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); - - // Return the merged PDF as a response - return ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(resource); - } - - private PDDocument mergeDocuments(List documents) throws IOException { - // Create a new empty document - PDDocument mergedDoc = new PDDocument(); - - // Iterate over the list of documents and add their pages to the merged document - for (PDDocument doc : documents) { - // Get all pages from the current document - PDPageTree pages = doc.getPages(); - // Iterate over the pages and add them to the merged document - for (PDPage page : pages) { - mergedDoc.addPage(page); - } - } - - // Return the merged document - return mergedDoc; - } - -} \ No newline at end of file diff --git a/src/main/java/stirling/software/SPDF/controller/RearrangePagesPDFController.java b/src/main/java/stirling/software/SPDF/controller/RearrangePagesPDFController.java deleted file mode 100644 index c07ee4e17..000000000 --- a/src/main/java/stirling/software/SPDF/controller/RearrangePagesPDFController.java +++ /dev/null @@ -1,108 +0,0 @@ -package stirling.software.SPDF.controller; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -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.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -@Controller -public class RearrangePagesPDFController { - - private static final Logger logger = LoggerFactory.getLogger(RearrangePagesPDFController.class); - - @GetMapping("/pdf-organizer") - public String pageOrganizer(Model model) { - model.addAttribute("currentPage", "pdf-organizer"); - return "pdf-organizer"; - } - - @PostMapping("/rearrange-pages") - public ResponseEntity rearrangePages(@RequestParam("fileInput") MultipartFile pdfFile, - @RequestParam("pageOrder") String pageOrder) { - try { - // Load the input PDF - PDDocument document = PDDocument.load(pdfFile.getInputStream()); - - // Split the page order string into an array of page numbers or range of numbers - String[] pageOrderArr = pageOrder.split(","); - List newPageOrder = new ArrayList(); - //int[] newPageOrder = new int[pageOrderArr.length]; - int totalPages = document.getNumberOfPages(); - - // loop through the page order array - for (String element : pageOrderArr) { - // check if the element contains a range of pages - if (element.contains("-")) { - // split the range into start and end page - String[] range = element.split("-"); - int start = Integer.parseInt(range[0]); - int end = Integer.parseInt(range[1]); - // check if the end page is greater than total pages - if (end > totalPages) { - end = totalPages; - } - // loop through the range of pages - for (int j = start; j <= end; j++) { - // print the current index - newPageOrder.add( j - 1); - } - } else { - // if the element is a single page - newPageOrder.add( Integer.parseInt(element) - 1); - } - } - - // Create a new list to hold the pages in the new order - List newPages = new ArrayList<>(); - for (int i = 0; i < newPageOrder.size(); i++) { - newPages.add(document.getPage(newPageOrder.get(i))); - } - - // Remove all the pages from the original document - for (int i = document.getNumberOfPages() - 1; i >= 0; i--) { - document.removePage(i); - } - - // Add the pages in the new order - for (PDPage page : newPages) { - document.addPage(page); - } - - // Save the rearranged PDF to a ByteArrayOutputStream - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - document.save(outputStream); - - // Close the original document - document.close(); - - // Prepare the response headers - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_PDF); - headers.setContentDispositionFormData("attachment", "rearranged.pdf"); - headers.setContentLength(outputStream.size()); - - // Return the response with the PDF data and headers - return new ResponseEntity<>(outputStream.toByteArray(), headers, HttpStatus.OK); - } catch (IOException e) { - - logger.error("Failed rearranging documents", e); - return null; - } - } - -} diff --git a/src/main/java/stirling/software/SPDF/controller/RotationController.java b/src/main/java/stirling/software/SPDF/controller/RotationController.java deleted file mode 100644 index 233b2067c..000000000 --- a/src/main/java/stirling/software/SPDF/controller/RotationController.java +++ /dev/null @@ -1,74 +0,0 @@ -package stirling.software.SPDF.controller; - -import java.io.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.ListIterator; - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageTree; -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.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import stirling.software.SPDF.utils.PdfUtils; - -@Controller -public class RotationController { - - private static final Logger logger = LoggerFactory.getLogger(RotationController.class); - - @GetMapping("/rotate-pdf") - public String rotatePdfForm(Model model) { - model.addAttribute("currentPage", "rotate-pdf"); - return "rotate-pdf"; - } - - @PostMapping("/rotate-pdf") - public ResponseEntity rotatePDF(@RequestParam("fileInput") MultipartFile pdfFile, - @RequestParam("angle") String angle) throws IOException { - - // Load the PDF document - PDDocument document = PDDocument.load(pdfFile.getBytes()); - - // Get the list of pages in the document - PDPageTree pages = document.getPages(); - - // Rotate all pages by the specified angle - Iterator iterPage = pages.iterator(); - - while (iterPage.hasNext()) { - PDPage page = iterPage.next(); - page.setRotation(Integer.valueOf(angle)); - } - - // Save the rearranged PDF to a ByteArrayOutputStream - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - document.save(outputStream); - - // Close the document - document.close(); - - // Prepare the response headers - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_PDF); - headers.setContentDispositionFormData("attachment", "output.pdf"); - headers.setContentLength(outputStream.size()); - - // Return the response with the PDF data and headers - return new ResponseEntity<>(outputStream.toByteArray(), headers, HttpStatus.OK); - - } - -} diff --git a/src/main/java/stirling/software/SPDF/controller/SplitPDFController.java b/src/main/java/stirling/software/SPDF/controller/SplitPDFController.java deleted file mode 100644 index c283e5b52..000000000 --- a/src/main/java/stirling/software/SPDF/controller/SplitPDFController.java +++ /dev/null @@ -1,142 +0,0 @@ -package stirling.software.SPDF.controller; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -@Controller -public class SplitPDFController { - - private static final Logger logger = LoggerFactory.getLogger(SplitPDFController.class); - - @GetMapping("/split-pdfs") - public String splitPdfForm(Model model) { - model.addAttribute("currentPage", "split-pdfs"); - return "split-pdfs"; - } - - @PostMapping("/split-pages") - public ResponseEntity splitPdf(@RequestParam("fileInput") MultipartFile file, - @RequestParam("pages") String pages) throws IOException { - // parse user input - - // open the pdf document - InputStream inputStream = file.getInputStream(); - PDDocument document = PDDocument.load(inputStream); - - List pageNumbers = new ArrayList<>(); - pages = pages.replaceAll("\\s+", ""); // remove whitespaces - if (pages.toLowerCase().equals("all")) { - for (int i = 0; i < document.getNumberOfPages(); i++) { - pageNumbers.add(i); - } - } else { - List pageNumbersStr = new ArrayList<>(Arrays.asList(pages.split(","))); - if (!pageNumbersStr.contains(String.valueOf(document.getNumberOfPages()))) { - String lastpage = String.valueOf(document.getNumberOfPages()); - pageNumbersStr.add(lastpage); - } - for (String page : pageNumbersStr) { - if (page.contains("-")) { - String[] range = page.split("-"); - int start = Integer.parseInt(range[0]); - int end = Integer.parseInt(range[1]); - for (int i = start; i <= end; i++) { - pageNumbers.add(i); - } - } else { - pageNumbers.add(Integer.parseInt(page)); - } - } - } - - logger.info("Splitting PDF into pages: {}", - pageNumbers.stream().map(String::valueOf).collect(Collectors.joining(","))); - - // split the document - List splitDocumentsBoas = new ArrayList<>(); - int currentPage = 0; - for (int pageNumber : pageNumbers) { - try (PDDocument splitDocument = new PDDocument()) { - for (int i = currentPage; i < pageNumber; i++) { - PDPage page = document.getPage(i); - splitDocument.addPage(page); - logger.debug("Adding page {} to split document", i); - } - currentPage = pageNumber; - logger.debug("Setting current page to {}", currentPage); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - splitDocument.save(baos); - - splitDocumentsBoas.add(baos); - } catch (Exception e) { - logger.error("Failed splitting documents and saving them", e); - throw e; - } - } - - // closing the original document - document.close(); - - // create the zip file - Path zipFile = Paths.get("split_documents.zip"); - URI uri = URI.create("jar:file:" + zipFile.toUri().getPath()); - Map env = new HashMap<>(); - env.put("create", "true"); - FileSystem zipfs = FileSystems.newFileSystem(uri, env); - - // loop through the split documents and write them to the zip file - for (int i = 0; i < splitDocumentsBoas.size(); i++) { - String fileName = "split_document_" + (i + 1) + ".pdf"; - ByteArrayOutputStream baos = splitDocumentsBoas.get(i); - byte[] pdf = baos.toByteArray(); - Path pathInZipfile = zipfs.getPath(fileName); - try (OutputStream os = Files.newOutputStream(pathInZipfile)) { - os.write(pdf); - logger.info("Wrote split document {} to zip file", fileName); - } catch (Exception e) { - logger.error("Failed writing to zip", e); - throw e; - } - } - zipfs.close(); - logger.info("Successfully created zip file with split documents: {}", zipFile.toString()); - byte[] data = Files.readAllBytes(zipFile); - ByteArrayResource resource = new ByteArrayResource(data); - new File("split_documents.zip").delete(); - // return the Resource in the response - return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=split_documents.zip") - .contentType(MediaType.APPLICATION_OCTET_STREAM).contentLength(resource.contentLength()).body(resource); - } -} diff --git a/src/main/java/stirling/software/SPDF/utils/PdfUtils.java b/src/main/java/stirling/software/SPDF/utils/PdfUtils.java deleted file mode 100644 index 9fc24f281..000000000 --- a/src/main/java/stirling/software/SPDF/utils/PdfUtils.java +++ /dev/null @@ -1,124 +0,0 @@ -package stirling.software.SPDF.utils; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Iterator; - -import javax.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriter; -import javax.imageio.stream.ImageOutputStream; - -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageContentStream; -import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; -import org.apache.pdfbox.rendering.ImageType; -import org.apache.pdfbox.rendering.PDFRenderer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PdfUtils { - - private static final Logger logger = LoggerFactory.getLogger(PdfUtils.class); - - public static byte[] convertToPdf(InputStream imageStream) throws IOException { - - // Create a File object for the image - File imageFile = new File("image.jpg"); - - try (FileOutputStream fos = new FileOutputStream(imageFile); InputStream input = imageStream) { - byte[] buffer = new byte[1024]; - int len; - // Read from the input stream and write to the file - while ((len = input.read(buffer)) != -1) { - fos.write(buffer, 0, len); - } - logger.info("Image successfully written to file: {}", imageFile.getAbsolutePath()); - } catch (IOException e) { - logger.error("Error writing image to file: {}", imageFile.getAbsolutePath(), e); - throw e; - } - - try (PDDocument doc = new PDDocument()) { - // Create a new PDF page - PDPage page = new PDPage(); - doc.addPage(page); - - // Create an image object from the image file - PDImageXObject image = PDImageXObject.createFromFileByContent(imageFile, doc); - - try (PDPageContentStream contentStream = new PDPageContentStream(doc, page)) { - // Draw the image onto the page - contentStream.drawImage(image, 0, 0); - logger.info("Image successfully added to PDF"); - } catch (IOException e) { - logger.error("Error adding image to PDF", e); - throw e; - } - - // Create a ByteArrayOutputStream to save the PDF to - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - doc.save(byteArrayOutputStream); - logger.info("PDF successfully saved to byte array"); - return byteArrayOutputStream.toByteArray(); - } - } - - public static byte[] convertFromPdf(byte[] inputStream, String imageType) throws IOException { - try (PDDocument document = PDDocument.load(new ByteArrayInputStream(inputStream))) { - // Create a PDFRenderer to convert the PDF to an image - PDFRenderer pdfRenderer = new PDFRenderer(document); - BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB); - - // Get an ImageWriter for the specified image type - Iterator writers = ImageIO.getImageWritersByFormatName(imageType); - ImageWriter writer = writers.next(); - - // Create a ByteArrayOutputStream to save the image to - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ImageOutputStream ios = ImageIO.createImageOutputStream(baos)) { - writer.setOutput(ios); - // Write the image to the output stream - writer.write(new IIOImage(bim, null, null)); - // Log that the image was successfully written to the byte array - logger.info("Image successfully written to byte array"); - } - return baos.toByteArray(); - } catch (IOException e) { - // Log an error message if there is an issue converting the PDF to an image - logger.error("Error converting PDF to image", e); - throw e; - } - } - - public static byte[] overlayImage(byte[] pdfBytes, byte[] imageBytes, float x, float y) throws IOException { - - try (PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes))) { - // Get the first page of the PDF - PDPage page = document.getPage(0); - try (PDPageContentStream contentStream = new PDPageContentStream(document, page, - PDPageContentStream.AppendMode.APPEND, true)) { - // Create an image object from the image bytes - PDImageXObject image = PDImageXObject.createFromByteArray(document, imageBytes, ""); - // Draw the image onto the page at the specified x and y coordinates - contentStream.drawImage(image, x, y); - logger.info("Image successfully overlayed onto PDF"); - } - // Create a ByteArrayOutputStream to save the PDF to - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - document.save(baos); - logger.info("PDF successfully saved to byte array"); - return baos.toByteArray(); - } catch (IOException e) { - // Log an error message if there is an issue overlaying the image onto the PDF - logger.error("Error overlaying image onto PDF", e); - throw e; - } - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index d49c5abdc..000000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,11 +0,0 @@ -spring.http.multipart.max-file-size=1GB -spring.http.multipart.max-request-size=1GB - -multipart.enabled=true -multipart.max-file-size=1000MB -multipart.max-request-size=1000MB - -spring.servlet.multipart.max-file-size=1000MB -spring.servlet.multipart.max-request-size=1000MB - -server.forward-headers-strategy=NATIVE diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index d6a58a9f7..000000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootLogger=ERROR,stdout -log4j.logger.com.endeca=INFO -# Logger for crawl metrics -log4j.logger.com.endeca.itl.web.metrics=INFO - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n \ No newline at end of file diff --git a/src/main/resources/static/dark-mode.css b/src/main/resources/static/dark-mode.css deleted file mode 100644 index 6c528702b..000000000 --- a/src/main/resources/static/dark-mode.css +++ /dev/null @@ -1,23 +0,0 @@ -/* Dark Mode Styles */ -body { - background-color: #333; - color: #fff; -} - -.dark-card { - background-color: #333 !important; - color: white; -} -.jumbotron { - background-color: #222; /* or any other dark color */ - color: #fff; /* or any other light color */ -} - -.list-group { - background-color: #222 !important; - color: fff !important; -} -.list-group-item { - background-color: #222 !important; - color: fff !important; -} \ No newline at end of file diff --git a/src/main/resources/static/favicon.png b/src/main/resources/static/favicon.png deleted file mode 100644 index b17ecf108c49c8245de410f7d8355dca8b8612bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4356 zcmV+f5&Q0mP))v;xZW*w!F7g90X844~Ae>QN9%8$e=6faE=Ygd9lr z>||#4nwd3gfA9NuW@dlyFMF@GW?cZ&m4Z}^!UK353$X-mpa>tK3}q-sIVwO96(~nJ z%20-Vco%E17z^+?9>7SXA_bz*DH;7R2J`S5w&D;NqYvSIyo!0aAN`Ol#nt&geF$da z73@TH%%MkfHFn|^%)}7+X3$5SF&gfn%gO79> z7GX46Ng)2IJ08NDXB%+3_ypEq3c5)+-s%!$p%67%MSs3)P=s7uDnWS>{ZwqyIQoVd zY`{b4Afc(!AS^;@augT+40vw?1gm_{dwMuYvQS|pR3u+Tpe7Ae6);@S3A2T?kL`Yfu;}j zpV2k`xe|^~epbi$pORpF^b@+pKV3rc*)w#Cf1+_qIm6H#oUBj3Ut0dbbPBZ?7Z@tD z`~qB7k`{FQsW>V@1Uh5j+F;-K$t$0r{V6&J6@MFSl>jtwaWL}*5@ouFHeMaXtf4tl zc#ZrczvKT8>H2Bq8jSQa{;QNn?&9grBZMWz1y#)B(lm!S1<7+{&7-hjeVcj z@n0tEe6;paT<&e(e}fcRb8q%?e}Vs!0*An}y^4R3O!p4SJHi28#Gix`DQ-x-%Zn2Z zpOnIe$g@<(e{~2CZHZ@B;!3sa{NItHhRhpO?mjwM3K~LZtBSv!?CBdyA6B&u^)IBD zA@u?k@%NVAe`sBet78Y?Eh%J({YI?ur%4e*?%QJP{>jeXVRuO^-NAdMfCl(3xAC{Y zJ}I98-s5)C_;@LvA zfUnWg<3(T{`JbG_<$RBa*qmzl8UM_m@OECP=T#%H;PyLgPvtCGcB%;_A=B##Q- zi8nA!nY*fZrlFAl{7lV}FKg*WXIRKdY#+njFW_WuWEI`%I9GEDyC@C+a{kF> zHKOS?70)$45 WfV;9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5{IU@OWujWb z^1xO4^!uCBU>uRa6uTTl5h7hF$4)4I<(WEU(H({=0l6|v+@wz~B+ z9(t)K-j>kM^F~~aI8y?$aY&*E@fETVr)rCQoQ(6O9WSWc(m9;E5-a02{)tFJ9S0{B?n72Qb@!aA1;!Z+!A^`ZeVk8?Zo*pB z8Ww&LM$6Z}6MY*m8}iZ832dnV4R?#2F>zItL5{`dL#xTs+ zV9a0_3NRGO5=cPoo$wAOjsG0A17?H{mfXMTv*|7M?^2euu{}7_Fq> z`YH*1kcqiifh{-~bLa=L1t@IR0000 \ No newline at end of file diff --git a/src/main/resources/static/general.css b/src/main/resources/static/general.css deleted file mode 100644 index 20e97c598..000000000 --- a/src/main/resources/static/general.css +++ /dev/null @@ -1,5 +0,0 @@ -#footer { - position: absolute; - bottom: 0; - width: 100%; -} diff --git a/src/main/resources/templates/add-image.html b/src/main/resources/templates/add-image.html deleted file mode 100644 index f0c81be0a..000000000 --- a/src/main/resources/templates/add-image.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - -S-PDF Add-Image - - - -
-
-
-
-
-
-

Add image to PDF

- - - -
- -
- -
-
- -
-
- -
-
- -
- -
- - -
-
-
-
- - - \ No newline at end of file diff --git a/src/main/resources/templates/common.html b/src/main/resources/templates/common.html deleted file mode 100644 index cd7932530..000000000 --- a/src/main/resources/templates/common.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - -
-
- - - - - -
\ No newline at end of file diff --git a/src/main/resources/templates/compress-pdf.html b/src/main/resources/templates/compress-pdf.html deleted file mode 100644 index fdf47a26d..000000000 --- a/src/main/resources/templates/compress-pdf.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - -S-PDF Add-Image - - - -
-
-
-
-
-
-

Compress PDF

- - - -
-

Warning: This process can take up to a minute depending on file-size

-
- -
-
- -
- - -
- - -
-
-
-
- - - \ No newline at end of file diff --git a/src/main/resources/templates/convert-pdf.html b/src/main/resources/templates/convert-pdf.html deleted file mode 100644 index caa89d055..000000000 --- a/src/main/resources/templates/convert-pdf.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - -S-PDF ConvertToPDF - - - -
-
-
-
-
-
-

Image to PDF

- -
-
- -
-

- - -
- -
-
-
-

-
-
-
-

PDF to img

-
-
- -
-
- -
- -
- - -
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/footer.html b/src/main/resources/templates/footer.html deleted file mode 100644 index b4c75af16..000000000 --- a/src/main/resources/templates/footer.html +++ /dev/null @@ -1,11 +0,0 @@ -
- - -
\ No newline at end of file diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html deleted file mode 100644 index d3b1c3c9a..000000000 --- a/src/main/resources/templates/home.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - S-PDF - - - -
- -
-
-

Stirling PDF

-

Your locally hosted one-stop-shop for all your - PDF needs. (Made 100% in ChatGPT in 1 day as a experiment)

-
-
- - - - -
-
-
-
-
-
Merge PDFs
-

Easily merge multiple PDFs into one.

- Go -
-
-
-
-
-
-
Split PDFs
-

Split PDFs into multiple documents

- Go -
-
-
-
-
-
-
Add image to PDF
-

Adds image/watermark to a PDF

- Go -
-
-
-
-
-
-
-
-
-
Convert to/from PDF
-

Convert images to/from PDF.

- Go -
-
-
- -
-
-
-
PDF Organizer
-

Remove/Rearrange pages in any order

- Go -
-
-
- -
-
-
-
Rotate PDFs
-

Easily rotate your PDFs.

- Go -
-
-
- -
-
-
- - - - - -
-
-
-
Compress PDFs
-

Compress PDFs to reduce their file size.

- Go -
-
-
- -
-
-
- - - \ No newline at end of file diff --git a/src/main/resources/templates/merge-pdfs.html b/src/main/resources/templates/merge-pdfs.html deleted file mode 100644 index b0a027d63..000000000 --- a/src/main/resources/templates/merge-pdfs.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - -S-PDF MergePDFs - - - - - -
-
-
-
-
-
-

Merge multiple PDFs (2+)

-
-
- -
- -
-
-
-
    -
    -
    - -
    -
    - - - - - - - - - - -
    -
    -
    -
    - - \ No newline at end of file diff --git a/src/main/resources/templates/navbar.html b/src/main/resources/templates/navbar.html deleted file mode 100644 index 0c7297f37..000000000 --- a/src/main/resources/templates/navbar.html +++ /dev/null @@ -1,49 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/templates/pdf-organizer.html b/src/main/resources/templates/pdf-organizer.html deleted file mode 100644 index 9e8e578f3..000000000 --- a/src/main/resources/templates/pdf-organizer.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - -S-PDF Organizer - - - -
    -
    -
    -
    -
    -
    -

    PDF Page Organizer

    - - - -
    -
    - -
    -
    - -
    - -
    - - -
    -
    -
    -
    - - \ No newline at end of file diff --git a/src/main/resources/templates/rotate-pdf.html b/src/main/resources/templates/rotate-pdf.html deleted file mode 100644 index 2eb00bd17..000000000 --- a/src/main/resources/templates/rotate-pdf.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - -S-PDF Add-Image - - - -
    -
    -
    -
    -
    -
    -

    Rotate PDF

    - - - -
    -
    - -
    - -
    - -
    - - -
    -
    -
    -
    - - - \ No newline at end of file diff --git a/src/main/resources/templates/split-pdfs.html b/src/main/resources/templates/split-pdfs.html deleted file mode 100644 index ce4fbb5d9..000000000 --- a/src/main/resources/templates/split-pdfs.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - -S-PDF Split PDFs - - - -
    -
    -
    -
    -
    -
    -

    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 10 page document into - 6 separate PDFS with:

    -

    Document #1: Page 1

    -

    Document #2: Page 2 and 3

    -

    Document #3: Page 4, 5 and 6

    -

    Document #4: Page 7

    -

    Document #5: Page 8

    -

    Document #6: Page 9 and 10

    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    -
    -
    -
    - - \ No newline at end of file