From 7acc716b80755cb8768d5bca90885db8fef02fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Sz=C3=BCcs?= <127139797+balazs-szucs@users.noreply.github.com> Date: Mon, 17 Nov 2025 12:39:05 +0100 Subject: [PATCH] feat(compress): expose linearize PDF option on the UI (#4843) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description of Changes TLDR: - Added a new checkbox in the UI for linearizing PDFs - Updated `CompressController` to support PDF linearization - Added new localization key for linearize option in messages properties file image --- ## Checklist ### General - [X] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [X] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/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/devGuide/HowToAddNewLanguage.md) (if applicable) - [X] I have performed a self-review of my own code - [X] 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/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [X] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [X] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. Signed-off-by: Balázs Szücs --- .../SPDF/controller/api/misc/CompressController.java | 4 ++-- app/core/src/main/resources/messages_en_GB.properties | 1 + .../src/main/resources/templates/misc/compress-pdf.html | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java index bb148a5a9..d253b67b0 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java @@ -774,11 +774,11 @@ public class CompressController { this.streamLength = image.getCOSObject().getLength(); this.imageType = getImageType(image); this.decodeParams = generateDecodeParamsHash(image); - this.metadataHash = this.generateMetadataHash(image); + this.metadataHash = ImageIdentity.generateMetadataHash(image); } // Generate hash of image metadata - private String generateMetadataHash(PDImageXObject image) { + private static String generateMetadataHash(PDImageXObject image) { try { StringBuilder metadata = new StringBuilder(); diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index e4c6378f1..eebbeb78f 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -1329,6 +1329,7 @@ compress.title=Compress compress.header=Compress PDF compress.credit=This service uses qpdf for PDF Compress/Optimisation. compress.grayscale.label=Apply Grayscale for Compression +compress.linearize.label=Linearize PDF for faster web viewing compress.selectText.1=Compression Settings compress.selectText.1.1=1-3 PDF compression,
4-6 lite image compression,
7-9 intense image compression Will dramatically reduce image quality compress.selectText.2=Optimisation level: diff --git a/app/core/src/main/resources/templates/misc/compress-pdf.html b/app/core/src/main/resources/templates/misc/compress-pdf.html index 550983a8c..b593eb8f3 100644 --- a/app/core/src/main/resources/templates/misc/compress-pdf.html +++ b/app/core/src/main/resources/templates/misc/compress-pdf.html @@ -45,6 +45,12 @@ + +
+ +