mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-24 12:36:13 +00:00
Compare commits
2 Commits
81d0e2cb5f
...
2c0677cbf4
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2c0677cbf4 | ||
![]() |
47bce86ae2 |
@ -124,20 +124,21 @@ public class FileToPdf {
|
|||||||
private static void zipDirectory(Path sourceDir, Path zipFilePath) throws IOException {
|
private static void zipDirectory(Path sourceDir, Path zipFilePath) throws IOException {
|
||||||
try (ZipOutputStream zos =
|
try (ZipOutputStream zos =
|
||||||
new ZipOutputStream(new FileOutputStream(zipFilePath.toFile()))) {
|
new ZipOutputStream(new FileOutputStream(zipFilePath.toFile()))) {
|
||||||
Files.walk(sourceDir)
|
try (Stream<Path> walk = Files.walk(sourceDir)) {
|
||||||
.filter(path -> !Files.isDirectory(path))
|
walk.filter(path -> !Files.isDirectory(path))
|
||||||
.forEach(
|
.forEach(
|
||||||
path -> {
|
path -> {
|
||||||
ZipEntry zipEntry =
|
ZipEntry zipEntry =
|
||||||
new ZipEntry(sourceDir.relativize(path).toString());
|
new ZipEntry(sourceDir.relativize(path).toString());
|
||||||
try {
|
try {
|
||||||
zos.putNextEntry(zipEntry);
|
zos.putNextEntry(zipEntry);
|
||||||
Files.copy(path, zos);
|
Files.copy(path, zos);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@ -150,10 +151,11 @@ public class ConvertImgPDFController {
|
|||||||
.runCommandWithOutputHandling(command);
|
.runCommandWithOutputHandling(command);
|
||||||
|
|
||||||
// Find all WebP files in the output directory
|
// Find all WebP files in the output directory
|
||||||
List<Path> webpFiles =
|
List<Path> webpFiles;
|
||||||
Files.walk(tempOutputDir)
|
try (Stream<Path> walkStream = Files.walk(tempOutputDir)) {
|
||||||
.filter(path -> path.toString().endsWith(".webp"))
|
webpFiles =
|
||||||
.toList();
|
walkStream.filter(path -> path.toString().endsWith(".webp")).toList();
|
||||||
|
}
|
||||||
|
|
||||||
if (webpFiles.isEmpty()) {
|
if (webpFiles.isEmpty()) {
|
||||||
log.error("No WebP files were created in: {}", tempOutputDir.toString());
|
log.error("No WebP files were created in: {}", tempOutputDir.toString());
|
||||||
|
@ -48,10 +48,12 @@ public class FilterController {
|
|||||||
String text = request.getText();
|
String text = request.getText();
|
||||||
String pageNumber = request.getPageNumbers();
|
String pageNumber = request.getPageNumbers();
|
||||||
|
|
||||||
PDDocument pdfDocument = pdfDocumentFactory.load(inputFile);
|
try (PDDocument pdfDocument = pdfDocumentFactory.load(inputFile)) {
|
||||||
if (PdfUtils.hasText(pdfDocument, pageNumber, text))
|
if (PdfUtils.hasText(pdfDocument, pageNumber, text)) {
|
||||||
return WebResponseUtils.pdfDocToWebResponse(
|
return WebResponseUtils.pdfDocToWebResponse(
|
||||||
pdfDocument, Filenames.toSimpleFileName(inputFile.getOriginalFilename()));
|
pdfDocument, Filenames.toSimpleFileName(inputFile.getOriginalFilename()));
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@ -142,7 +143,10 @@ public class ExtractImageScansController {
|
|||||||
.runCommandWithOutputHandling(command);
|
.runCommandWithOutputHandling(command);
|
||||||
|
|
||||||
// Read the output photos in temp directory
|
// Read the output photos in temp directory
|
||||||
List<Path> tempOutputFiles = Files.list(tempDir).sorted().toList();
|
List<Path> tempOutputFiles;
|
||||||
|
try (Stream<Path> listStream = Files.list(tempDir)) {
|
||||||
|
tempOutputFiles = listStream.sorted().toList();
|
||||||
|
}
|
||||||
for (Path tempOutputFile : tempOutputFiles) {
|
for (Path tempOutputFile : tempOutputFiles) {
|
||||||
byte[] imageBytes = Files.readAllBytes(tempOutputFile);
|
byte[] imageBytes = Files.readAllBytes(tempOutputFile);
|
||||||
processedImageBytes.add(imageBytes);
|
processedImageBytes.add(imageBytes);
|
||||||
|
@ -7,6 +7,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thymeleaf.util.StringUtils;
|
import org.thymeleaf.util.StringUtils;
|
||||||
@ -66,10 +67,11 @@ public class SignatureService {
|
|||||||
|
|
||||||
private List<SignatureFile> getSignaturesFromFolder(Path folder, String category)
|
private List<SignatureFile> getSignaturesFromFolder(Path folder, String category)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return Files.list(folder)
|
try (Stream<Path> stream = Files.list(folder)) {
|
||||||
.filter(path -> isImageFile(path))
|
return stream.filter(this::isImageFile)
|
||||||
.map(path -> new SignatureFile(path.getFileName().toString(), category))
|
.map(path -> new SignatureFile(path.getFileName().toString(), category))
|
||||||
.toList();
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSignatureBytes(String username, String fileName) throws IOException {
|
public byte[] getSignatureBytes(String username, String fileName) throws IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user