2023-04-28 23:18:10 +01:00
|
|
|
package stirling.software.SPDF.controller.web;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Hidden;
|
2023-06-25 09:16:32 +01:00
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2023-04-28 23:18:10 +01:00
|
|
|
|
|
|
|
@Controller
|
2023-06-25 09:16:32 +01:00
|
|
|
@Tag(name = "Other", description = "Other APIs")
|
2023-04-28 23:18:10 +01:00
|
|
|
public class OtherWebController {
|
|
|
|
@GetMapping("/compress-pdf")
|
|
|
|
@Hidden
|
|
|
|
public String compressPdfForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "compress-pdf");
|
|
|
|
return "other/compress-pdf";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/extract-image-scans")
|
|
|
|
@Hidden
|
|
|
|
public ModelAndView extractImageScansForm() {
|
|
|
|
ModelAndView modelAndView = new ModelAndView("other/extract-image-scans");
|
|
|
|
modelAndView.addObject("currentPage", "extract-image-scans");
|
|
|
|
return modelAndView;
|
|
|
|
}
|
2023-08-06 21:56:02 +01:00
|
|
|
|
|
|
|
@GetMapping("/show-javascript")
|
|
|
|
@Hidden
|
|
|
|
public String extractJavascriptForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "show-javascript");
|
|
|
|
return "other/show-javascript";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-04 21:45:35 +01:00
|
|
|
@GetMapping("/add-page-numbers")
|
|
|
|
@Hidden
|
|
|
|
public String addPageNumbersForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "add-page-numbers");
|
|
|
|
return "other/add-page-numbers";
|
|
|
|
}
|
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
@GetMapping("/extract-images")
|
|
|
|
@Hidden
|
|
|
|
public String extractImagesForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "extract-images");
|
|
|
|
return "other/extract-images";
|
|
|
|
}
|
|
|
|
|
2023-05-04 23:22:33 +01:00
|
|
|
@GetMapping("/flatten")
|
|
|
|
@Hidden
|
|
|
|
public String flattenForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "flatten");
|
|
|
|
return "other/flatten";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
|
|
|
|
@GetMapping("/change-metadata")
|
|
|
|
@Hidden
|
|
|
|
public String addWatermarkForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "change-metadata");
|
|
|
|
return "other/change-metadata";
|
|
|
|
}
|
|
|
|
|
2023-05-08 00:17:20 +01:00
|
|
|
@GetMapping("/compare")
|
|
|
|
@Hidden
|
|
|
|
public String compareForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "compare");
|
|
|
|
return "other/compare";
|
|
|
|
}
|
2023-04-28 23:18:10 +01:00
|
|
|
|
|
|
|
public List<String> getAvailableTesseractLanguages() {
|
|
|
|
String tessdataDir = "/usr/share/tesseract-ocr/4.00/tessdata";
|
|
|
|
File[] files = new File(tessdataDir).listFiles();
|
|
|
|
if (files == null) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
return Arrays.stream(files).filter(file -> file.getName().endsWith(".traineddata")).map(file -> file.getName().replace(".traineddata", ""))
|
|
|
|
.filter(lang -> !lang.equalsIgnoreCase("osd")).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/ocr-pdf")
|
|
|
|
@Hidden
|
|
|
|
public ModelAndView ocrPdfPage() {
|
|
|
|
ModelAndView modelAndView = new ModelAndView("other/ocr-pdf");
|
2023-06-08 20:25:55 +01:00
|
|
|
List<String> languages = getAvailableTesseractLanguages();
|
|
|
|
Collections.sort(languages);
|
|
|
|
modelAndView.addObject("languages", languages);
|
2023-04-28 23:18:10 +01:00
|
|
|
modelAndView.addObject("currentPage", "ocr-pdf");
|
|
|
|
return modelAndView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/add-image")
|
|
|
|
@Hidden
|
|
|
|
public String overlayImage(Model model) {
|
|
|
|
model.addAttribute("currentPage", "add-image");
|
|
|
|
return "other/add-image";
|
|
|
|
}
|
2023-05-01 21:53:10 +01:00
|
|
|
|
|
|
|
@GetMapping("/adjust-contrast")
|
|
|
|
@Hidden
|
|
|
|
public String contrast(Model model) {
|
|
|
|
model.addAttribute("currentPage", "adjust-contrast");
|
|
|
|
return "other/adjust-contrast";
|
|
|
|
}
|
|
|
|
|
2023-05-06 12:36:31 +01:00
|
|
|
@GetMapping("/repair")
|
|
|
|
@Hidden
|
|
|
|
public String repairForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "repair");
|
|
|
|
return "other/repair";
|
|
|
|
}
|
2023-05-01 21:53:10 +01:00
|
|
|
|
2023-05-08 12:18:48 +01:00
|
|
|
@GetMapping("/remove-blanks")
|
|
|
|
@Hidden
|
|
|
|
public String removeBlanksForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "remove-blanks");
|
|
|
|
return "other/remove-blanks";
|
|
|
|
}
|
|
|
|
|
2023-05-27 14:23:25 +01:00
|
|
|
@GetMapping("/multi-page-layout")
|
|
|
|
@Hidden
|
|
|
|
public String multiPageLayoutForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "multi-page-layout");
|
|
|
|
return "other/multi-page-layout";
|
|
|
|
}
|
|
|
|
|
2023-05-31 21:39:40 +02:00
|
|
|
@GetMapping("/scale-pages")
|
|
|
|
@Hidden
|
|
|
|
public String scalePagesFrom(Model model) {
|
|
|
|
model.addAttribute("currentPage", "scale-pages");
|
|
|
|
return "other/scale-pages";
|
|
|
|
}
|
2023-05-27 14:23:25 +01:00
|
|
|
|
2023-06-03 22:56:15 +01:00
|
|
|
@GetMapping("/auto-crop")
|
|
|
|
@Hidden
|
|
|
|
public String autoCropForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "auto-crop");
|
|
|
|
return "other/auto-crop";
|
|
|
|
}
|
|
|
|
|
2023-07-04 23:25:21 +01:00
|
|
|
@GetMapping("/auto-rename")
|
|
|
|
@Hidden
|
|
|
|
public String autoRenameForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "auto-rename");
|
|
|
|
return "other/auto-rename";
|
|
|
|
}
|
|
|
|
|
2023-07-05 22:21:43 +01:00
|
|
|
|
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|