possible fixes for overlay
This commit is contained in:
parent
39345bb6bb
commit
5774a22b64
2 changed files with 14 additions and 10 deletions
|
@ -8,7 +8,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'stirling.software'
|
group = 'stirling.software'
|
||||||
version = '0.17.0'
|
version = '0.17.1'
|
||||||
sourceCompatibility = '17'
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
|
@ -55,8 +55,9 @@ public class PdfOverlayController {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
overlay.overlay(overlayGuide).save(outputStream);
|
overlay.overlay(overlayGuide).save(outputStream);
|
||||||
byte[] data = outputStream.toByteArray();
|
byte[] data = outputStream.toByteArray();
|
||||||
|
String outputFilename = baseFile.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_overlayed.pdf"; // Remove file extension and append .pdf
|
||||||
return WebResponseUtils.bytesToWebResponse(data, "overlaid.pdf", MediaType.APPLICATION_PDF);
|
|
||||||
|
return WebResponseUtils.bytesToWebResponse(data, outputFilename, MediaType.APPLICATION_PDF);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
for (File overlayPdfFile : overlayPdfFiles) {
|
for (File overlayPdfFile : overlayPdfFiles) {
|
||||||
|
@ -84,17 +85,20 @@ public class PdfOverlayController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sequentialOverlay(Map<Integer, String> overlayGuide, File[] overlayFiles, int basePageCount) throws IOException {
|
private void sequentialOverlay(Map<Integer, String> overlayGuide, File[] overlayFiles, int basePageCount) throws IOException {
|
||||||
int currentPage = 1;
|
if (overlayFiles.length != 1 || basePageCount != PDDocument.load(overlayFiles[0]).getNumberOfPages()) {
|
||||||
for (File overlayFile : overlayFiles) {
|
throw new IllegalArgumentException("Overlay file count and base page count must match for sequential overlay.");
|
||||||
try (PDDocument overlayPdf = PDDocument.load(overlayFile)) {
|
}
|
||||||
for (int i = 0; i < overlayPdf.getNumberOfPages(); i++) {
|
|
||||||
if (currentPage > basePageCount) break;
|
File overlayFile = overlayFiles[0];
|
||||||
overlayGuide.put(currentPage++, overlayFile.getAbsolutePath());
|
try (PDDocument overlayPdf = PDDocument.load(overlayFile)) {
|
||||||
}
|
for (int i = 1; i <= overlayPdf.getNumberOfPages(); i++) {
|
||||||
|
if (i > basePageCount) break;
|
||||||
|
overlayGuide.put(i, overlayFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void interleavedOverlay(Map<Integer, String> overlayGuide, File[] overlayFiles, int basePageCount) throws IOException {
|
private void interleavedOverlay(Map<Integer, String> overlayGuide, File[] overlayFiles, int basePageCount) throws IOException {
|
||||||
for (int i = 0; i < basePageCount; i++) {
|
for (int i = 0; i < basePageCount; i++) {
|
||||||
File overlayFile = overlayFiles[i % overlayFiles.length];
|
File overlayFile = overlayFiles[i % overlayFiles.length];
|
||||||
|
|
Loading…
Reference in a new issue