🤖 format everything with pre-commit by <stirlingbot> ()

Auto-generated by [create-pull-request][1] with **stirlingbot**

[1]: https://github.com/peter-evans/create-pull-request

Signed-off-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
This commit is contained in:
stirlingbot[bot] 2025-03-05 08:39:30 +00:00 committed by GitHub
parent 15d5387fdc
commit 0dd483a435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions
src/main/java/stirling/software/SPDF

@ -72,7 +72,7 @@ public class ConvertWebsiteToPDF {
List<String> command = new ArrayList<>(); List<String> command = new ArrayList<>();
command.add(runtimePathConfig.getWeasyPrintPath()); command.add(runtimePathConfig.getWeasyPrintPath());
command.add(URL); command.add(URL);
command.add("--pdf-forms"); command.add("--pdf-forms");
command.add(tempOutputFile.toString()); command.add(tempOutputFile.toString());
ProcessExecutorResult returnCode = ProcessExecutorResult returnCode =

@ -203,7 +203,7 @@ public class CompressController {
// Choose appropriate format and compression // Choose appropriate format and compression
String format = bufferedImage.getColorModel().hasAlpha() ? "png" : "jpeg"; String format = bufferedImage.getColorModel().hasAlpha() ? "png" : "jpeg";
// First get the actual size of the original image by encoding it to the chosen format // First get the actual size of the original image by encoding it to the chosen format
ByteArrayOutputStream originalImageStream = new ByteArrayOutputStream(); ByteArrayOutputStream originalImageStream = new ByteArrayOutputStream();
if (format.equals("jpeg")) { if (format.equals("jpeg")) {
@ -365,7 +365,7 @@ public class CompressController {
default -> 1.0; // No image scaling for levels 1-3 default -> 1.0; // No image scaling for levels 1-3
}; };
} }
// New method for JPEG quality based on optimization level // New method for JPEG quality based on optimization level
private float getJpegQualityForLevel(int optimizeLevel) { private float getJpegQualityForLevel(int optimizeLevel) {
return switch (optimizeLevel) { return switch (optimizeLevel) {
@ -416,10 +416,10 @@ public class CompressController {
boolean sizeMet = false; boolean sizeMet = false;
boolean imageCompressionApplied = false; // Track if we've already compressed images boolean imageCompressionApplied = false; // Track if we've already compressed images
boolean qpdfCompressionApplied = false; boolean qpdfCompressionApplied = false;
while (!sizeMet && optimizeLevel <= 9) { while (!sizeMet && optimizeLevel <= 9) {
// Apply appropriate compression based on level // Apply appropriate compression based on level
// Levels 4-9: Apply image compression // Levels 4-9: Apply image compression
if (optimizeLevel >= 4 && !imageCompressionApplied) { if (optimizeLevel >= 4 && !imageCompressionApplied) {
double scaleFactor = getScaleFactorForLevel(optimizeLevel); double scaleFactor = getScaleFactorForLevel(optimizeLevel);
@ -427,12 +427,12 @@ public class CompressController {
compressImagesInPDF(tempInputFile, scaleFactor, jpegQuality); compressImagesInPDF(tempInputFile, scaleFactor, jpegQuality);
imageCompressionApplied = true; // Mark that we've compressed images imageCompressionApplied = true; // Mark that we've compressed images
} }
// All levels (1-9): Apply QPDF compression // All levels (1-9): Apply QPDF compression
if (!qpdfCompressionApplied) { if (!qpdfCompressionApplied) {
long preQpdfSize = Files.size(tempInputFile); long preQpdfSize = Files.size(tempInputFile);
log.info("Pre-QPDF file size: {}", GeneralUtils.formatBytes(preQpdfSize)); log.info("Pre-QPDF file size: {}", GeneralUtils.formatBytes(preQpdfSize));
// For levels 1-3, map to qpdf compression levels 1-9 // For levels 1-3, map to qpdf compression levels 1-9
int qpdfCompressionLevel = optimizeLevel; int qpdfCompressionLevel = optimizeLevel;
if (optimizeLevel <= 3) { if (optimizeLevel <= 3) {
@ -440,7 +440,7 @@ public class CompressController {
} else { } else {
qpdfCompressionLevel = 9; // Max QPDF compression for levels 4-9 qpdfCompressionLevel = 9; // Max QPDF compression for levels 4-9
} }
// Run QPDF optimization // Run QPDF optimization
List<String> command = new ArrayList<>(); List<String> command = new ArrayList<>();
command.add("qpdf"); command.add("qpdf");
@ -474,7 +474,7 @@ public class CompressController {
"Post-QPDF file size: {} (reduced by {:.1f}%)", "Post-QPDF file size: {} (reduced by {:.1f}%)",
GeneralUtils.formatBytes(postQpdfSize), GeneralUtils.formatBytes(postQpdfSize),
qpdfReduction); qpdfReduction);
} else { } else {
tempOutputFile = tempInputFile; tempOutputFile = tempInputFile;
} }
@ -550,4 +550,4 @@ public class CompressController {
} }
return Math.min(9, currentLevel + 1); return Math.min(9, currentLevel + 1);
} }
} }

@ -53,7 +53,7 @@ public class FileToPdf {
command.add("-e"); command.add("-e");
command.add("utf-8"); command.add("utf-8");
command.add("-v"); command.add("-v");
command.add("--pdf-forms"); command.add("--pdf-forms");
command.add(tempInputFile.toString()); command.add(tempInputFile.toString());
command.add(tempOutputFile.toString()); command.add(tempOutputFile.toString());