feat(replace-and-invert-colour): Add CMYK color space conversion with prepress preset for PDF processing (#4494)

This commit is contained in:
Balázs Szücs
2025-09-28 16:39:20 +01:00
committed by GitHub
parent 4ad039d034
commit 07392ed25e
8 changed files with 139 additions and 19 deletions
@@ -5,6 +5,7 @@ import org.springframework.web.multipart.MultipartFile;
import stirling.software.common.model.api.misc.HighContrastColorCombination;
import stirling.software.common.model.api.misc.ReplaceAndInvert;
import stirling.software.common.util.misc.ColorSpaceConversionStrategy;
import stirling.software.common.util.misc.CustomColorReplaceStrategy;
import stirling.software.common.util.misc.InvertFullColorStrategy;
import stirling.software.common.util.misc.ReplaceAndInvertColorStrategy;
@@ -19,21 +20,17 @@ public class ReplaceAndInvertColorFactory {
String backGroundColor,
String textColor) {
if (replaceAndInvertOption == ReplaceAndInvert.CUSTOM_COLOR
|| replaceAndInvertOption == ReplaceAndInvert.HIGH_CONTRAST_COLOR) {
return new CustomColorReplaceStrategy(
file,
replaceAndInvertOption,
textColor,
backGroundColor,
highContrastColorCombination);
} else if (replaceAndInvertOption == ReplaceAndInvert.FULL_INVERSION) {
return new InvertFullColorStrategy(file, replaceAndInvertOption);
}
return null;
return switch (replaceAndInvertOption) {
case CUSTOM_COLOR, HIGH_CONTRAST_COLOR ->
new CustomColorReplaceStrategy(
file,
replaceAndInvertOption,
textColor,
backGroundColor,
highContrastColorCombination);
case FULL_INVERSION -> new InvertFullColorStrategy(file, replaceAndInvertOption);
case COLOR_SPACE_CONVERSION ->
new ColorSpaceConversionStrategy(file, replaceAndInvertOption);
};
}
}
@@ -400,6 +400,7 @@ public class EndpointConfiguration {
/* Ghostscript */
addEndpointToGroup("Ghostscript", "repair");
addEndpointToGroup("Ghostscript", "compress-pdf");
addEndpointToGroup("Ghostscript", "replace-invert-pdf");
/* tesseract */
addEndpointToGroup("tesseract", "ocr-pdf");
@@ -31,8 +31,8 @@ public class ReplaceAndInvertColorController {
@Operation(
summary = "Replace-Invert Color PDF",
description =
"This endpoint accepts a PDF file and option of invert all colors or replace"
+ " text and background colors. Input:PDF Output:PDF Type:SISO")
"This endpoint accepts a PDF file and provides options to invert all colors, replace"
+ " text and background colors, or convert to CMYK color space for printing. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<InputStreamResource> replaceAndInvertColor(
@ModelAttribute ReplaceAndInvertColorRequest request) throws IOException {
@@ -17,7 +17,12 @@ public class ReplaceAndInvertColorRequest extends PDFFile {
description = "Replace and Invert color options of a pdf.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "HIGH_CONTRAST_COLOR",
allowableValues = {"HIGH_CONTRAST_COLOR", "CUSTOM_COLOR", "FULL_INVERSION"})
allowableValues = {
"HIGH_CONTRAST_COLOR",
"CUSTOM_COLOR",
"FULL_INVERSION",
"COLOR_SPACE_CONVERSION"
})
private ReplaceAndInvert replaceAndInvertOption;
@Schema(