mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-05-11 16:55:54 +00:00
pixel changes, redact color fix, version bump, aggressive compression (#3502)
# Description of Changes Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
parent
fd1e854778
commit
e5e7935456
@ -29,7 +29,7 @@ ext {
|
||||
}
|
||||
|
||||
group = "stirling.software"
|
||||
version = "0.46.0"
|
||||
version = "0.46.1"
|
||||
|
||||
java {
|
||||
// 17 is lowest but we support and recommend 21
|
||||
|
@ -34,6 +34,11 @@ public class EEAppConfig {
|
||||
return licenseKeyChecker.getPremiumLicenseEnabledResult() != License.NORMAL;
|
||||
}
|
||||
|
||||
@Bean(name = "license")
|
||||
public String licenseType() {
|
||||
return licenseKeyChecker.getPremiumLicenseEnabledResult().name();
|
||||
}
|
||||
|
||||
@Bean(name = "runningEE")
|
||||
public boolean runningEnterprise() {
|
||||
return licenseKeyChecker.getPremiumLicenseEnabledResult() == License.ENTERPRISE;
|
||||
|
@ -5,6 +5,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
@ -33,6 +35,8 @@ public class AppConfig {
|
||||
|
||||
private final ApplicationProperties applicationProperties;
|
||||
|
||||
private final Environment env;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "system.customHTMLFiles", havingValue = "true")
|
||||
public SpringTemplateEngine templateEngine(ResourceLoader resourceLoader) {
|
||||
@ -193,4 +197,37 @@ public class AppConfig {
|
||||
public String uuid() {
|
||||
return applicationProperties.getAutomaticallyGenerated().getUUID();
|
||||
}
|
||||
|
||||
@Bean(name = "disablePixel")
|
||||
public boolean disablePixel() {
|
||||
return Boolean.getBoolean(env.getProperty("DISABLE_PIXEL"));
|
||||
}
|
||||
|
||||
@Bean(name = "machineType")
|
||||
public String determineMachineType() {
|
||||
try {
|
||||
boolean isDocker = runningInDocker();
|
||||
boolean isKubernetes = System.getenv("KUBERNETES_SERVICE_HOST") != null;
|
||||
boolean isBrowserOpen = "true".equalsIgnoreCase(env.getProperty("BROWSER_OPEN"));
|
||||
|
||||
if (isKubernetes) {
|
||||
return "Kubernetes";
|
||||
} else if (isDocker) {
|
||||
return "Docker";
|
||||
} else if (isBrowserOpen) {
|
||||
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||
if (os.contains("win")) {
|
||||
return "Client-windows";
|
||||
} else if (os.contains("mac")) {
|
||||
return "Client-mac";
|
||||
} else {
|
||||
return "Client-unix";
|
||||
}
|
||||
} else {
|
||||
return "Server-jar";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -627,23 +627,30 @@ public class CompressController {
|
||||
// Scale factors for different optimization levels
|
||||
private double getScaleFactorForLevel(int optimizeLevel) {
|
||||
return switch (optimizeLevel) {
|
||||
case 4 -> 0.9; // 90% - lite compression
|
||||
case 5 -> 0.8; // 80% - lite compression
|
||||
case 6 -> 0.7; // 70% - lite compression
|
||||
case 7 -> 0.6; // 60% - intense compression
|
||||
case 8 -> 0.5; // 50% - intense compression
|
||||
case 9, 10 -> 0.4; // 40% - intense compression
|
||||
default -> 1.0; // No scaling for levels 1-3
|
||||
case 3 -> 0.85;
|
||||
case 4 -> 0.75;
|
||||
case 5 -> 0.65;
|
||||
case 6 -> 0.55;
|
||||
case 7 -> 0.45;
|
||||
case 8 -> 0.35;
|
||||
case 9 -> 0.25;
|
||||
case 10 -> 0.15;
|
||||
default -> 1.0;
|
||||
};
|
||||
}
|
||||
|
||||
// JPEG quality for different optimization levels
|
||||
private float getJpegQualityForLevel(int optimizeLevel) {
|
||||
return switch (optimizeLevel) {
|
||||
case 7 -> 0.8f; // 80% quality
|
||||
case 8 -> 0.6f; // 60% quality
|
||||
case 9, 10 -> 0.4f; // 40% quality
|
||||
default -> 0.7f; // 70% quality for levels 1-6
|
||||
case 3 -> 0.85f;
|
||||
case 4 -> 0.80f;
|
||||
case 5 -> 0.75f;
|
||||
case 6 -> 0.70f;
|
||||
case 7 -> 0.60f;
|
||||
case 8 -> 0.50f;
|
||||
case 9 -> 0.35f;
|
||||
case 10 -> 0.2f;
|
||||
default -> 0.7f;
|
||||
};
|
||||
}
|
||||
|
||||
@ -698,7 +705,7 @@ public class CompressController {
|
||||
|
||||
while (!sizeMet && optimizeLevel <= 9) {
|
||||
// Apply image compression for levels 4-9
|
||||
if ((optimizeLevel >= 4 || Boolean.TRUE.equals(convertToGrayscale))
|
||||
if ((optimizeLevel >= 3 || Boolean.TRUE.equals(convertToGrayscale))
|
||||
&& !imageCompressionApplied) {
|
||||
double scaleFactor = getScaleFactorForLevel(optimizeLevel);
|
||||
float jpegQuality = getJpegQualityForLevel(optimizeLevel);
|
||||
@ -790,10 +797,14 @@ public class CompressController {
|
||||
log.info("Pre-QPDF file size: {}", GeneralUtils.formatBytes(preQpdfSize));
|
||||
|
||||
// Map optimization levels to QPDF compression levels
|
||||
int qpdfCompressionLevel =
|
||||
optimizeLevel <= 3
|
||||
? optimizeLevel * 3 // Level 1->3, 2->6, 3->9
|
||||
: 9; // Max compression for levels 4-9
|
||||
int qpdfCompressionLevel;
|
||||
if (optimizeLevel == 1) {
|
||||
qpdfCompressionLevel = 5;
|
||||
} else if (optimizeLevel == 2) {
|
||||
qpdfCompressionLevel = 9;
|
||||
} else {
|
||||
qpdfCompressionLevel = 9;
|
||||
}
|
||||
|
||||
// Create output file for QPDF
|
||||
Path qpdfOutputFile = Files.createTempFile("qpdf_output_", ".pdf");
|
||||
|
@ -170,15 +170,16 @@ public class RedactController {
|
||||
}
|
||||
|
||||
private Color decodeOrDefault(String hex, Color defaultColor) {
|
||||
Color color = null;
|
||||
try {
|
||||
color = Color.decode(hex);
|
||||
if (hex != null && !hex.startsWith("#")) {
|
||||
hex = "#" + hex;
|
||||
}
|
||||
return Color.decode(hex);
|
||||
} catch (Exception e) {
|
||||
color = defaultColor;
|
||||
return defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
private List<Integer> getPageNumbers(ManualRedactPdfRequest request, int pagesCount) {
|
||||
String pageNumbersInput = request.getPageNumbers();
|
||||
|
@ -23,7 +23,7 @@ public class RedactPdfRequest extends PDFFile {
|
||||
@Schema(description = "Whether to use whole word search", defaultValue = "false")
|
||||
private boolean wholeWordSearch;
|
||||
|
||||
@Schema(description = "The color for redaction", defaultValue = "#000000")
|
||||
@Schema(description = "Hexadecimal color code for redaction, e.g. #FF0000 or 000000", defaultValue = "#000000")
|
||||
private String redactColor = "#000000";
|
||||
|
||||
@Schema(description = "Custom padding for redaction", type = "number")
|
||||
|
@ -41,7 +41,13 @@
|
||||
<link rel="stylesheet" th:href="@{'/css/bootstrap-icons.min.css'}">
|
||||
|
||||
<!-- Pixel, doesn't collect any PII-->
|
||||
<img referrerpolicy="no-referrer-when-downgrade" src="https://pixel.stirlingpdf.com/a.png?x-pxid=4f5fa02f-a065-4efb-bb2c-24509a4b6b92" style="position: absolute; visibility: hidden;"/>
|
||||
<img th:if="${!@disablePixel}" referrerpolicy="no-referrer-when-downgrade"
|
||||
th:src="'https://pixel.stirlingpdf.com/a.png?x-pxid=4f5fa02f-a065-4efb-bb2c-24509a4b6b92'
|
||||
+ '&machineType=' + ${@machineType}
|
||||
+ '&appVersion=' + ${@appVersion}
|
||||
+ '&licenseType=' + ${@license}
|
||||
+ '&loginEnabled=' + ${@loginEnabled}"
|
||||
style="position: absolute; visibility: hidden;" />
|
||||
|
||||
<!-- Custom -->
|
||||
<link rel="stylesheet" th:href="@{'/css/general.css'}">
|
||||
|
@ -43,7 +43,7 @@
|
||||
th:insert="~{fragments/navbarEntry :: navbarEntry ('multi-tool', 'construction', 'home.multiTool.title', 'home.multiTool.desc', 'multiTool.tags', 'organize')}">
|
||||
</div>
|
||||
<div class="newfeature"
|
||||
th:insert="~{fragments/navbarEntry :: navbarEntry('validate-signature', 'verified', 'home.validateSignature.title', 'home.validateSignature.desc', 'validateSignature.tags', 'security')}">
|
||||
th:insert="~{fragments/navbarEntry :: navbarEntry('compress-pdf', 'zoom_in_map', 'home.compressPdfs.title', 'home.compressPdfs.desc', 'compressPDFs.tags', 'advance')}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user