diff --git a/build.gradle b/build.gradle index 312f6d6d..73b8a05f 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'stirling.software' -version = '0.17.0' +version = '0.17.1' sourceCompatibility = '17' repositories { diff --git a/src/main/java/stirling/software/SPDF/controller/api/PdfOverlayController.java b/src/main/java/stirling/software/SPDF/controller/api/PdfOverlayController.java index 57de5f64..1dc81e9f 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/PdfOverlayController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/PdfOverlayController.java @@ -55,8 +55,9 @@ public class PdfOverlayController { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); overlay.overlay(overlayGuide).save(outputStream); byte[] data = outputStream.toByteArray(); - - return WebResponseUtils.bytesToWebResponse(data, "overlaid.pdf", MediaType.APPLICATION_PDF); + String outputFilename = baseFile.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_overlayed.pdf"; // Remove file extension and append .pdf + + return WebResponseUtils.bytesToWebResponse(data, outputFilename, MediaType.APPLICATION_PDF); } } finally { for (File overlayPdfFile : overlayPdfFiles) { @@ -84,17 +85,20 @@ public class PdfOverlayController { } private void sequentialOverlay(Map overlayGuide, File[] overlayFiles, int basePageCount) throws IOException { - int currentPage = 1; - for (File overlayFile : overlayFiles) { - try (PDDocument overlayPdf = PDDocument.load(overlayFile)) { - for (int i = 0; i < overlayPdf.getNumberOfPages(); i++) { - if (currentPage > basePageCount) break; - overlayGuide.put(currentPage++, overlayFile.getAbsolutePath()); - } + if (overlayFiles.length != 1 || basePageCount != PDDocument.load(overlayFiles[0]).getNumberOfPages()) { + throw new IllegalArgumentException("Overlay file count and base page count must match for sequential overlay."); + } + + File overlayFile = overlayFiles[0]; + 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 overlayGuide, File[] overlayFiles, int basePageCount) throws IOException { for (int i = 0; i < basePageCount; i++) { File overlayFile = overlayFiles[i % overlayFiles.length];