mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-04-19 19:21:18 +00:00
🤖 format everything with pre-commit by <stirlingbot> (#3103)
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:
parent
15d5387fdc
commit
0dd483a435
@ -72,7 +72,7 @@ public class ConvertWebsiteToPDF {
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(runtimePathConfig.getWeasyPrintPath());
|
||||
command.add(URL);
|
||||
command.add("--pdf-forms");
|
||||
command.add("--pdf-forms");
|
||||
command.add(tempOutputFile.toString());
|
||||
|
||||
ProcessExecutorResult returnCode =
|
||||
|
@ -203,7 +203,7 @@ public class CompressController {
|
||||
|
||||
// Choose appropriate format and compression
|
||||
String format = bufferedImage.getColorModel().hasAlpha() ? "png" : "jpeg";
|
||||
|
||||
|
||||
// First get the actual size of the original image by encoding it to the chosen format
|
||||
ByteArrayOutputStream originalImageStream = new ByteArrayOutputStream();
|
||||
if (format.equals("jpeg")) {
|
||||
@ -365,7 +365,7 @@ public class CompressController {
|
||||
default -> 1.0; // No image scaling for levels 1-3
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// New method for JPEG quality based on optimization level
|
||||
private float getJpegQualityForLevel(int optimizeLevel) {
|
||||
return switch (optimizeLevel) {
|
||||
@ -416,10 +416,10 @@ public class CompressController {
|
||||
boolean sizeMet = false;
|
||||
boolean imageCompressionApplied = false; // Track if we've already compressed images
|
||||
boolean qpdfCompressionApplied = false;
|
||||
|
||||
|
||||
while (!sizeMet && optimizeLevel <= 9) {
|
||||
// Apply appropriate compression based on level
|
||||
|
||||
|
||||
// Levels 4-9: Apply image compression
|
||||
if (optimizeLevel >= 4 && !imageCompressionApplied) {
|
||||
double scaleFactor = getScaleFactorForLevel(optimizeLevel);
|
||||
@ -427,12 +427,12 @@ public class CompressController {
|
||||
compressImagesInPDF(tempInputFile, scaleFactor, jpegQuality);
|
||||
imageCompressionApplied = true; // Mark that we've compressed images
|
||||
}
|
||||
|
||||
|
||||
// All levels (1-9): Apply QPDF compression
|
||||
if (!qpdfCompressionApplied) {
|
||||
long preQpdfSize = Files.size(tempInputFile);
|
||||
log.info("Pre-QPDF file size: {}", GeneralUtils.formatBytes(preQpdfSize));
|
||||
|
||||
|
||||
// For levels 1-3, map to qpdf compression levels 1-9
|
||||
int qpdfCompressionLevel = optimizeLevel;
|
||||
if (optimizeLevel <= 3) {
|
||||
@ -440,7 +440,7 @@ public class CompressController {
|
||||
} else {
|
||||
qpdfCompressionLevel = 9; // Max QPDF compression for levels 4-9
|
||||
}
|
||||
|
||||
|
||||
// Run QPDF optimization
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add("qpdf");
|
||||
@ -474,7 +474,7 @@ public class CompressController {
|
||||
"Post-QPDF file size: {} (reduced by {:.1f}%)",
|
||||
GeneralUtils.formatBytes(postQpdfSize),
|
||||
qpdfReduction);
|
||||
|
||||
|
||||
} else {
|
||||
tempOutputFile = tempInputFile;
|
||||
}
|
||||
@ -550,4 +550,4 @@ public class CompressController {
|
||||
}
|
||||
return Math.min(9, currentLevel + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class FileToPdf {
|
||||
command.add("-e");
|
||||
command.add("utf-8");
|
||||
command.add("-v");
|
||||
command.add("--pdf-forms");
|
||||
command.add("--pdf-forms");
|
||||
command.add(tempInputFile.toString());
|
||||
command.add(tempOutputFile.toString());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user