forked from Stirling-Tools/Stirling-PDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,552 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/stirling/software/SPDF/Factories/ReplaceAndInvertColorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package stirling.software.SPDF.Factories; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination; | ||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert; | ||
import stirling.software.SPDF.utils.misc.CustomColorReplaceStrategy; | ||
import stirling.software.SPDF.utils.misc.InvertFullColorStrategy; | ||
import stirling.software.SPDF.utils.misc.ReplaceAndInvertColorStrategy; | ||
|
||
@Component | ||
public class ReplaceAndInvertColorFactory { | ||
|
||
public ReplaceAndInvertColorStrategy replaceAndInvert( | ||
MultipartFile file, | ||
ReplaceAndInvert replaceAndInvertOption, | ||
HighContrastColorCombination highContrastColorCombination, | ||
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; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...main/java/stirling/software/SPDF/controller/api/misc/ReplaceAndInvertColorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package stirling.software.SPDF.controller.api.misc; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.io.InputStreamResource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
|
||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvertColorRequest; | ||
import stirling.software.SPDF.service.misc.ReplaceAndInvertColorService; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/misc") | ||
public class ReplaceAndInvertColorController { | ||
|
||
private ReplaceAndInvertColorService replaceAndInvertColorService; | ||
|
||
@Autowired | ||
public ReplaceAndInvertColorController( | ||
ReplaceAndInvertColorService replaceAndInvertColorService) { | ||
this.replaceAndInvertColorService = replaceAndInvertColorService; | ||
} | ||
|
||
@PostMapping(consumes = "multipart/form-data", value = "/replace-invert-pdf") | ||
@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") | ||
public ResponseEntity<InputStreamResource> replaceAndInvertColor( | ||
@ModelAttribute ReplaceAndInvertColorRequest replaceAndInvertColorRequest) | ||
throws IOException { | ||
|
||
InputStreamResource resource = | ||
replaceAndInvertColorService.replaceAndInvertColor( | ||
replaceAndInvertColorRequest.getFileInput(), | ||
replaceAndInvertColorRequest.getReplaceAndInvertOption(), | ||
replaceAndInvertColorRequest.getHighContrastColorCombination(), | ||
replaceAndInvertColorRequest.getBackGroundColor(), | ||
replaceAndInvertColorRequest.getTextColor()); | ||
|
||
// Return the modified PDF as a downloadable file | ||
return ResponseEntity.ok() | ||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=inverted.pdf") | ||
.contentType(MediaType.APPLICATION_PDF) | ||
.body(resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/stirling/software/SPDF/model/api/misc/HighContrastColorCombination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package stirling.software.SPDF.model.api.misc; | ||
|
||
public enum HighContrastColorCombination { | ||
WHITE_TEXT_ON_BLACK, | ||
BLACK_TEXT_ON_WHITE, | ||
YELLOW_TEXT_ON_BLACK, | ||
GREEN_TEXT_ON_BLACK, | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/stirling/software/SPDF/model/api/misc/ReplaceAndInvert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package stirling.software.SPDF.model.api.misc; | ||
|
||
public enum ReplaceAndInvert { | ||
HIGH_CONTRAST_COLOR, | ||
CUSTOM_COLOR, | ||
FULL_INVERSION, | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/stirling/software/SPDF/model/api/misc/ReplaceAndInvertColorRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package stirling.software.SPDF.model.api.misc; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import stirling.software.SPDF.model.api.PDFFile; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class ReplaceAndInvertColorRequest extends PDFFile { | ||
|
||
@Schema( | ||
description = "Replace and Invert color options of a pdf.", | ||
allowableValues = {"HIGH_CONTRAST_COLOR", "CUSTOM_COLOR", "FULL_INVERSION"}) | ||
private ReplaceAndInvert replaceAndInvertOption; | ||
|
||
@Schema( | ||
description = | ||
"If HIGH_CONTRAST_COLOR option selected, then pick the default color option for text and background.", | ||
allowableValues = { | ||
"WHITE_TEXT_ON_BLACK", | ||
"BLACK_TEXT_ON_WHITE", | ||
"YELLOW_TEXT_ON_BLACK", | ||
"GREEN_TEXT_ON_BLACK" | ||
}) | ||
private HighContrastColorCombination highContrastColorCombination; | ||
|
||
@Schema( | ||
description = | ||
"If CUSTOM_COLOR option selected, then pick the custom color for background. " | ||
+ "Expected color value should be 24bit decimal value of a color") | ||
private String backGroundColor; | ||
|
||
@Schema( | ||
description = | ||
"If CUSTOM_COLOR option selected, then pick the custom color for text. " | ||
+ "Expected color value should be 24bit decimal value of a color") | ||
private String textColor; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/stirling/software/SPDF/service/misc/ReplaceAndInvertColorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package stirling.software.SPDF.service.misc; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.io.InputStreamResource; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import stirling.software.SPDF.Factories.ReplaceAndInvertColorFactory; | ||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination; | ||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert; | ||
import stirling.software.SPDF.utils.misc.ReplaceAndInvertColorStrategy; | ||
|
||
@Service | ||
public class ReplaceAndInvertColorService { | ||
private ReplaceAndInvertColorFactory replaceAndInvertColorFactory; | ||
|
||
@Autowired | ||
public ReplaceAndInvertColorService(ReplaceAndInvertColorFactory replaceAndInvertColorFactory) { | ||
this.replaceAndInvertColorFactory = replaceAndInvertColorFactory; | ||
} | ||
|
||
public InputStreamResource replaceAndInvertColor( | ||
MultipartFile file, | ||
ReplaceAndInvert replaceAndInvertOption, | ||
HighContrastColorCombination highContrastColorCombination, | ||
String backGroundColor, | ||
String textColor) | ||
throws IOException { | ||
|
||
ReplaceAndInvertColorStrategy replaceColorStrategy = | ||
replaceAndInvertColorFactory.replaceAndInvert( | ||
file, | ||
replaceAndInvertOption, | ||
highContrastColorCombination, | ||
backGroundColor, | ||
textColor); | ||
|
||
return replaceColorStrategy.replace(); | ||
} | ||
} |
Oops, something went wrong.