diff --git a/app/common/src/main/java/stirling/software/common/util/PdfUtils.java b/app/common/src/main/java/stirling/software/common/util/PdfUtils.java index 6f4305bd3..ff7e64302 100644 --- a/app/common/src/main/java/stirling/software/common/util/PdfUtils.java +++ b/app/common/src/main/java/stirling/software/common/util/PdfUtils.java @@ -142,7 +142,8 @@ public class PdfUtils { ImageType colorType, boolean singleImage, int DPI, - String filename) + String filename, + boolean includeAnnotations) throws IOException, Exception { // Validate and limit DPI to prevent excessive memory usage @@ -163,6 +164,9 @@ public class PdfUtils { try (PDDocument document = pdfDocumentFactory.load(inputStream)) { PDFRenderer pdfRenderer = new PDFRenderer(document); pdfRenderer.setSubsamplingAllowed(true); + if (!includeAnnotations) { + pdfRenderer.setAnnotationsFilter(annotation -> false); + } int pageCount = document.getNumberOfPages(); // Create a ByteArrayOutputStream to save the image(s) to diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java index 5eff72a4a..bb34a71ab 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java @@ -66,6 +66,7 @@ public class ConvertImgPDFController { String colorType = request.getColorType(); int dpi = request.getDpi(); String pageNumbers = request.getPageNumbers(); + boolean includeAnnotations = Boolean.TRUE.equals(request.getIncludeAnnotations()); Path tempFile = null; Path tempOutputDir = null; Path tempPdfPath = null; @@ -101,7 +102,8 @@ public class ConvertImgPDFController { colorTypeResult, singleImage, dpi, - filename); + filename, + includeAnnotations); if (result == null || result.length == 0) { log.error("resultant bytes for {} is null, error converting ", filename); } diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java index 149676946..dbbd9f0eb 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/converters/ConvertToImageRequest.java @@ -39,4 +39,9 @@ public class ConvertToImageRequest extends PDFWithPageNums { defaultValue = "300", requiredMode = Schema.RequiredMode.REQUIRED) private Integer dpi; + + @Schema( + description = "Include annotations such as comments in the output image(s)", + defaultValue = "false") + private Boolean includeAnnotations; } diff --git a/app/core/src/main/resources/messages_en_GB.properties b/app/core/src/main/resources/messages_en_GB.properties index 3414a33f2..e529defe1 100644 --- a/app/core/src/main/resources/messages_en_GB.properties +++ b/app/core/src/main/resources/messages_en_GB.properties @@ -1439,6 +1439,7 @@ pdfToImage.dpi=DPI (The server limit is {0} dpi) pdfToImage.submit=Convert pdfToImage.info=Python is not installed. Required for WebP conversion. pdfToImage.placeholder=(e.g. 1,2,8 or 4,7,12-16 or 2n-1) +pdfToImage.includeAnnotations=Include annotations (comments, highlights etc.) #addPassword diff --git a/app/core/src/main/resources/templates/convert/pdf-to-img.html b/app/core/src/main/resources/templates/convert/pdf-to-img.html index 78c7ca901..8cd0df5ec 100644 --- a/app/core/src/main/resources/templates/convert/pdf-to-img.html +++ b/app/core/src/main/resources/templates/convert/pdf-to-img.html @@ -73,6 +73,10 @@ +