Further Fixes
This commit is contained in:
parent
bf995f989c
commit
33a6a7869c
5 changed files with 45 additions and 60 deletions
|
@ -8,7 +8,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = 'stirling.software'
|
||||
version = '0.11.1'
|
||||
version = '0.11.2'
|
||||
sourceCompatibility = '17'
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ConvertImgPDFController {
|
|||
@Parameter(description = "Choose between a single image containing all pages or separate images for each page", schema = @Schema(allowableValues = {"single", "multiple"}))
|
||||
String singleOrMultiple,
|
||||
@RequestParam("colorType")
|
||||
@Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"rgb", "greyscale", "blackwhite"}))
|
||||
@Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"color", "greyscale", "blackwhite"}))
|
||||
String colorType,
|
||||
@RequestParam("dpi")
|
||||
@Parameter(description = "The DPI (dots per inch) for the output image(s)")
|
||||
|
@ -94,7 +94,7 @@ public class ConvertImgPDFController {
|
|||
@Parameter(description = "Whether to stretch the images to fit the PDF page or maintain the aspect ratio", example = "false")
|
||||
boolean stretchToFit,
|
||||
@RequestParam("colorType")
|
||||
@Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"rgb", "greyscale", "blackwhite"}))
|
||||
@Parameter(description = "The color type of the output image(s)", schema = @Schema(allowableValues = {"color", "greyscale", "blackwhite"}))
|
||||
String colorType,
|
||||
@RequestParam(defaultValue = "false", name = "autoRotate")
|
||||
@Parameter(description = "Whether to automatically rotate the images to better fit the PDF page", example = "true")
|
||||
|
|
|
@ -1,35 +1,25 @@
|
|||
package stirling.software.SPDF.controller.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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 java.util.stream.Stream;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.ResourcePatternUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
@ -128,45 +118,28 @@ public class GeneralWebController {
|
|||
model.addAttribute("fonts", getFontNames());
|
||||
return "sign";
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private List<String> getFontNames() {
|
||||
List<String> fontNames = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// Get the directory URL from classpath
|
||||
URL dirURL = getClass().getClassLoader().getResource("static/fonts");
|
||||
Resource[] resources = ResourcePatternUtils.getResourcePatternResolver(resourceLoader)
|
||||
.getResources("classpath:static/fonts/*.woff2");
|
||||
|
||||
if (dirURL != null && dirURL.getProtocol().equals("file")) {
|
||||
// If running from the file system (e.g., IDE)
|
||||
fontNames.addAll(
|
||||
Files.list(Paths.get(dirURL.toURI()))
|
||||
.map(java.nio.file.Path::getFileName)
|
||||
.map(java.nio.file.Path::toString)
|
||||
.filter(name -> name.endsWith(".woff2"))
|
||||
.map(name -> name.substring(0, name.length() - 6)) // Remove .woff2 extension
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
} else {
|
||||
// If running from a JAR file
|
||||
// Resources in JAR go through a different URL protocol.
|
||||
// In this case, we'll use a different approach to list them.
|
||||
|
||||
// Create a link to the resource. This assumes resources are at the root of the JAR.
|
||||
URI uri = getClass().getResource("/").toURI();
|
||||
FileSystem fileSystem = FileSystems.newFileSystem(uri, new HashMap<>());
|
||||
Path myPath = fileSystem.getPath("/static/fonts/");
|
||||
Files.walk(myPath, 1)
|
||||
.filter(path -> !Files.isDirectory(path))
|
||||
.map(path -> path.getFileName().toString())
|
||||
.filter(name -> name.endsWith(".woff2"))
|
||||
.map(name -> name.substring(0, name.length() - 6)) // Remove .woff2 extension
|
||||
.forEach(fontNames::add);
|
||||
fileSystem.close();
|
||||
}
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
return Arrays.stream(resources)
|
||||
.map(resource -> {
|
||||
try {
|
||||
String filename = resource.getFilename();
|
||||
return filename.substring(0, filename.length() - 6); // Remove .woff2 extension
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error processing filename", e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to read font directory", e);
|
||||
}
|
||||
|
||||
return fontNames;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -155,10 +155,21 @@ async function submitMultiPdfForm(url, files) {
|
|||
jszip = new JSZip();
|
||||
}
|
||||
|
||||
|
||||
// Get the form with the method attribute set to POST
|
||||
let postForm = document.querySelector('form[method="POST"]');
|
||||
|
||||
// Get existing form data
|
||||
let formData = new FormData($('form')[0]);
|
||||
let formData;
|
||||
if (postForm) {
|
||||
formData = new FormData($(postForm)[0]); // Convert the form to a jQuery object and get the raw DOM element
|
||||
} else {
|
||||
console.log("No form with POST method found.");
|
||||
}
|
||||
//Remove file to reuse parameters for other runs
|
||||
formData.delete('fileInput');
|
||||
|
||||
|
||||
const CONCURRENCY_LIMIT = 8;
|
||||
const chunks = [];
|
||||
for (let i = 0; i < Array.from(files).length; i += CONCURRENCY_LIMIT) {
|
||||
|
@ -169,10 +180,11 @@ async function submitMultiPdfForm(url, files) {
|
|||
const promises = chunk.map(async file => {
|
||||
let fileFormData = new FormData();
|
||||
fileFormData.append('fileInput', file);
|
||||
|
||||
console.log(fileFormData);
|
||||
// Add other form data
|
||||
for (let pair of formData.entries()) {
|
||||
fileFormData.append(pair[0], pair[1]);
|
||||
console.log(pair[0]+ ', ' + pair[1]);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label th:text="#{pdfToImage.colorType}"></label>
|
||||
<select class="form-control" name="colorType">
|
||||
<select class="form-control" id="colorType" name="colorType">
|
||||
<option value="color" th:text="#{pdfToImage.color}"></option>
|
||||
<option value="greyscale" th:text="#{pdfToImage.grey}"></option>
|
||||
<option value="blackwhite" th:text="#{pdfToImage.blackwhite}"></option>
|
||||
|
|
Loading…
Reference in a new issue