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-09-14 14:30:39 +01:00
|
|
|
@Tag(name = "Misc", description = "Miscellaneous 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");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/compress-pdf";
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
@GetMapping("/extract-image-scans")
|
|
|
|
@Hidden
|
|
|
|
public ModelAndView extractImageScansForm() {
|
2023-09-13 00:46:30 +01:00
|
|
|
ModelAndView modelAndView = new ModelAndView("misc/extract-image-scans");
|
2023-04-28 23:18:10 +01:00
|
|
|
modelAndView.addObject("currentPage", "extract-image-scans");
|
|
|
|
return modelAndView;
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-08-06 21:56:02 +01:00
|
|
|
@GetMapping("/show-javascript")
|
|
|
|
@Hidden
|
|
|
|
public String extractJavascriptForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "show-javascript");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/show-javascript";
|
2023-08-06 21:56:02 +01:00
|
|
|
}
|
2024-01-28 17:39:07 +00:00
|
|
|
|
2024-01-28 17:36:17 +00:00
|
|
|
@GetMapping("/stamp")
|
|
|
|
@Hidden
|
|
|
|
public String stampForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "stamp");
|
|
|
|
return "misc/stamp";
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-07-04 21:45:35 +01:00
|
|
|
@GetMapping("/add-page-numbers")
|
|
|
|
@Hidden
|
|
|
|
public String addPageNumbersForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "add-page-numbers");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/add-page-numbers";
|
2023-07-04 21:45:35 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
@GetMapping("/extract-images")
|
|
|
|
@Hidden
|
|
|
|
public String extractImagesForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "extract-images");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/extract-images";
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-05-04 23:22:33 +01:00
|
|
|
@GetMapping("/flatten")
|
|
|
|
@Hidden
|
|
|
|
public String flattenForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "flatten");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/flatten";
|
2023-05-04 23:22:33 +01:00
|
|
|
}
|
2023-04-28 23:18:10 +01:00
|
|
|
|
|
|
|
@GetMapping("/change-metadata")
|
|
|
|
@Hidden
|
|
|
|
public String addWatermarkForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "change-metadata");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/change-metadata";
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-05-08 00:17:20 +01:00
|
|
|
@GetMapping("/compare")
|
|
|
|
@Hidden
|
|
|
|
public String compareForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "compare");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/compare";
|
2023-05-08 00:17:20 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
public List<String> getAvailableTesseractLanguages() {
|
2023-12-10 22:02:30 +00:00
|
|
|
String tessdataDir = "/usr/share/tesseract-ocr/5/tessdata";
|
2023-04-28 23:18:10 +01:00
|
|
|
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() {
|
2023-09-13 00:46:30 +01:00
|
|
|
ModelAndView modelAndView = new ModelAndView("misc/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;
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-04-28 23:18:10 +01:00
|
|
|
@GetMapping("/add-image")
|
|
|
|
@Hidden
|
|
|
|
public String overlayImage(Model model) {
|
|
|
|
model.addAttribute("currentPage", "add-image");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/add-image";
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-05-01 21:53:10 +01:00
|
|
|
@GetMapping("/adjust-contrast")
|
|
|
|
@Hidden
|
|
|
|
public String contrast(Model model) {
|
|
|
|
model.addAttribute("currentPage", "adjust-contrast");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/adjust-contrast";
|
2023-05-01 21:53:10 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-05-06 12:36:31 +01:00
|
|
|
@GetMapping("/repair")
|
|
|
|
@Hidden
|
|
|
|
public String repairForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "repair");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/repair";
|
2023-05-06 12:36:31 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-05-08 12:18:48 +01:00
|
|
|
@GetMapping("/remove-blanks")
|
|
|
|
@Hidden
|
|
|
|
public String removeBlanksForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "remove-blanks");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/remove-blanks";
|
2023-05-27 14:23:25 +01:00
|
|
|
}
|
2023-12-23 13:47:21 -05:00
|
|
|
|
|
|
|
@GetMapping("/remove-annotations")
|
|
|
|
@Hidden
|
|
|
|
public String removeAnnotationsForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "remove-annotations");
|
|
|
|
return "misc/remove-annotations";
|
|
|
|
}
|
2023-09-13 00:46:30 +01:00
|
|
|
|
2023-06-03 22:56:15 +01:00
|
|
|
@GetMapping("/auto-crop")
|
|
|
|
@Hidden
|
|
|
|
public String autoCropForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "auto-crop");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/auto-crop";
|
2023-06-03 22:56:15 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2023-07-04 23:25:21 +01:00
|
|
|
@GetMapping("/auto-rename")
|
|
|
|
@Hidden
|
|
|
|
public String autoRenameForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "auto-rename");
|
2023-09-12 00:42:22 +01:00
|
|
|
return "misc/auto-rename";
|
2023-07-04 23:25:21 +01:00
|
|
|
}
|
2023-04-28 23:18:10 +01:00
|
|
|
}
|