mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-08 17:51:20 +02:00
feat: add annotation option to PDF to image
This commit is contained in:
parent
4b6ac87419
commit
24ff95600c
@ -142,7 +142,8 @@ public class PdfUtils {
|
|||||||
ImageType colorType,
|
ImageType colorType,
|
||||||
boolean singleImage,
|
boolean singleImage,
|
||||||
int DPI,
|
int DPI,
|
||||||
String filename)
|
String filename,
|
||||||
|
boolean includeAnnotations)
|
||||||
throws IOException, Exception {
|
throws IOException, Exception {
|
||||||
|
|
||||||
// Validate and limit DPI to prevent excessive memory usage
|
// Validate and limit DPI to prevent excessive memory usage
|
||||||
@ -163,6 +164,9 @@ public class PdfUtils {
|
|||||||
try (PDDocument document = pdfDocumentFactory.load(inputStream)) {
|
try (PDDocument document = pdfDocumentFactory.load(inputStream)) {
|
||||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||||
pdfRenderer.setSubsamplingAllowed(true);
|
pdfRenderer.setSubsamplingAllowed(true);
|
||||||
|
if (!includeAnnotations) {
|
||||||
|
pdfRenderer.setAnnotationsFilter(annotation -> false);
|
||||||
|
}
|
||||||
int pageCount = document.getNumberOfPages();
|
int pageCount = document.getNumberOfPages();
|
||||||
|
|
||||||
// Create a ByteArrayOutputStream to save the image(s) to
|
// Create a ByteArrayOutputStream to save the image(s) to
|
||||||
|
@ -66,6 +66,7 @@ public class ConvertImgPDFController {
|
|||||||
String colorType = request.getColorType();
|
String colorType = request.getColorType();
|
||||||
int dpi = request.getDpi();
|
int dpi = request.getDpi();
|
||||||
String pageNumbers = request.getPageNumbers();
|
String pageNumbers = request.getPageNumbers();
|
||||||
|
boolean includeAnnotations = Boolean.TRUE.equals(request.getIncludeAnnotations());
|
||||||
Path tempFile = null;
|
Path tempFile = null;
|
||||||
Path tempOutputDir = null;
|
Path tempOutputDir = null;
|
||||||
Path tempPdfPath = null;
|
Path tempPdfPath = null;
|
||||||
@ -101,7 +102,8 @@ public class ConvertImgPDFController {
|
|||||||
colorTypeResult,
|
colorTypeResult,
|
||||||
singleImage,
|
singleImage,
|
||||||
dpi,
|
dpi,
|
||||||
filename);
|
filename,
|
||||||
|
includeAnnotations);
|
||||||
if (result == null || result.length == 0) {
|
if (result == null || result.length == 0) {
|
||||||
log.error("resultant bytes for {} is null, error converting ", filename);
|
log.error("resultant bytes for {} is null, error converting ", filename);
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,9 @@ public class ConvertToImageRequest extends PDFWithPageNums {
|
|||||||
defaultValue = "300",
|
defaultValue = "300",
|
||||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Integer dpi;
|
private Integer dpi;
|
||||||
|
|
||||||
|
@Schema(
|
||||||
|
description = "Include annotations such as comments in the output image(s)",
|
||||||
|
defaultValue = "false")
|
||||||
|
private Boolean includeAnnotations;
|
||||||
}
|
}
|
||||||
|
@ -1439,6 +1439,7 @@ pdfToImage.dpi=DPI (The server limit is {0} dpi)
|
|||||||
pdfToImage.submit=Convert
|
pdfToImage.submit=Convert
|
||||||
pdfToImage.info=Python is not installed. Required for WebP conversion.
|
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.placeholder=(e.g. 1,2,8 or 4,7,12-16 or 2n-1)
|
||||||
|
pdfToImage.includeAnnotations=Include annotations (comments, etc.)
|
||||||
|
|
||||||
|
|
||||||
#addPassword
|
#addPassword
|
||||||
|
@ -73,6 +73,10 @@
|
|||||||
<option value="blackwhite" th:text="#{pdfToImage.blackwhite}"></option>
|
<option value="blackwhite" th:text="#{pdfToImage.blackwhite}"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="includeAnnotations" name="includeAnnotations">
|
||||||
|
<label class="form-check-label" for="includeAnnotations" th:text="#{pdfToImage.includeAnnotations}"></label>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="dpi">DPI:</label>
|
<label for="dpi">DPI:</label>
|
||||||
<input type="number" name="dpi" class="form-control" id="dpi" min="1" step="1" value="300" required>
|
<input type="number" name="dpi" class="form-control" id="dpi" min="1" step="1" value="300" required>
|
||||||
|
Loading…
Reference in New Issue
Block a user