mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
feat(compress): add PDF linearization option using QPDF
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
parent
74223d69ad
commit
27c704951d
@ -791,6 +791,16 @@ public class CompressController {
|
|||||||
currentFile = originalFile;
|
currentFile = originalFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply linearization as final step if requested
|
||||||
|
if (Boolean.TRUE.equals(request.getLinearize()) && isQpdfEnabled()) {
|
||||||
|
try {
|
||||||
|
applyLinearization(currentFile, tempFiles);
|
||||||
|
log.info("PDF linearization applied successfully");
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("PDF linearization failed, continuing without linearization", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String outputFilename =
|
String outputFilename =
|
||||||
GeneralUtils.generateFilename(
|
GeneralUtils.generateFilename(
|
||||||
inputFile.getOriginalFilename(), "_Optimized.pdf");
|
inputFile.getOriginalFilename(), "_Optimized.pdf");
|
||||||
@ -810,6 +820,36 @@ public class CompressController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply PDF linearization using QPDF
|
||||||
|
private void applyLinearization(Path currentFile, List<Path> tempFiles) throws IOException {
|
||||||
|
log.info("Applying PDF linearization to: {}", currentFile);
|
||||||
|
|
||||||
|
// Create output file for linearization
|
||||||
|
Path linearizedOutputFile = Files.createTempFile("linearized_output_", ".pdf");
|
||||||
|
tempFiles.add(linearizedOutputFile);
|
||||||
|
|
||||||
|
// Build QPDF command for linearization only
|
||||||
|
List<String> command = new ArrayList<>();
|
||||||
|
command.add("qpdf");
|
||||||
|
command.add("--linearize");
|
||||||
|
command.add(currentFile.toString());
|
||||||
|
command.add(linearizedOutputFile.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
ProcessExecutorResult returnCode =
|
||||||
|
ProcessExecutor.getInstance(ProcessExecutor.Processes.QPDF)
|
||||||
|
.runCommandWithOutputHandling(command);
|
||||||
|
|
||||||
|
// Update current file to the linearized output
|
||||||
|
Files.copy(linearizedOutputFile, currentFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
log.info("PDF linearization completed successfully");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("PDF linearization failed", e);
|
||||||
|
throw new IOException("PDF linearization failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run Ghostscript compression
|
// Run Ghostscript compression
|
||||||
private void applyGhostscriptCompression(
|
private void applyGhostscriptCompression(
|
||||||
OptimizePdfRequest request, int optimizeLevel, Path currentFile, List<Path> tempFiles)
|
OptimizePdfRequest request, int optimizeLevel, Path currentFile, List<Path> tempFiles)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user