1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-11-05 07:20:12 +01:00

Merge pull request #730 from Stirling-Tools/fix-remove-blank-pages

fix: remove blank pages not handling EXIT_FAILURE code properly
This commit is contained in:
Eric 2024-01-22 10:58:59 -05:00 committed by GitHub
commit f85c8ea5ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 12 deletions

View File

@ -115,4 +115,4 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
return false; return false;
} }
} }

View File

@ -121,8 +121,8 @@ public class SplitPdfBySectionsController {
subDoc, subPage, AppendMode.APPEND, true, true)) { subDoc, subPage, AppendMode.APPEND, true, true)) {
// Set clipping area and position // Set clipping area and position
float translateX = -subPageWidth * i; float translateX = -subPageWidth * i;
//float translateY = height - subPageHeight * (verticalDivisions - j); // float translateY = height - subPageHeight * (verticalDivisions - j);
float translateY = -subPageHeight * (verticalDivisions - 1 - j); float translateY = -subPageHeight * (verticalDivisions - 1 - j);
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();

View File

@ -33,7 +33,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.misc.RemoveBlankPagesRequest; import stirling.software.SPDF.model.api.misc.RemoveBlankPagesRequest;
import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.PdfUtils;
import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor;
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -85,7 +84,7 @@ public class BlankPageController {
List<String> command = List<String> command =
new ArrayList<>( new ArrayList<>(
Arrays.asList( Arrays.asList(
"python3", "python",
System.getProperty("user.dir") System.getProperty("user.dir")
+ "/scripts/detect-blank-pages.py", + "/scripts/detect-blank-pages.py",
tempFile.toString(), tempFile.toString(),
@ -94,18 +93,25 @@ public class BlankPageController {
"--white_percent", "--white_percent",
String.valueOf(whitePercent))); String.valueOf(whitePercent)));
Boolean blank = false;
// Run CLI command // Run CLI command
ProcessExecutorResult returnCode = try {
ProcessExecutor.getInstance(ProcessExecutor.Processes.PYTHON_OPENCV) ProcessExecutor.getInstance(ProcessExecutor.Processes.PYTHON_OPENCV)
.runCommandWithOutputHandling(command); .runCommandWithOutputHandling(command);
} catch (IOException e) {
// From detect-blank-pages.py
// Return code 1: The image is considered blank.
// Return code 0: The image is not considered blank.
// Since the process returned with a failure code, it should be blank.
blank = true;
}
// does contain data if (blank) {
if (returnCode.getRc() == 0) { System.out.println("Skipping, Image was blank for page #" + pageIndex);
} else {
System.out.println( System.out.println(
"page " + pageIndex + " has image which is not blank"); "page " + pageIndex + " has image which is not blank");
pagesToKeepIndex.add(pageIndex); pagesToKeepIndex.add(pageIndex);
} else {
System.out.println("Skipping, Image was blank for page #" + pageIndex);
} }
} }
} }