diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/StampController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/StampController.java index e5478b9e38d..efbd59d4c66 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/StampController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/StampController.java @@ -67,6 +67,7 @@ public ResponseEntity addStamp(@ModelAttribute AddStampRequest request) float overrideY = request.getOverrideY(); // New field for Y override int pagingPosition = request.getPagingPosition(); int firstPageRate = request.getFirstPageRate(); + boolean autoCrop = request.isAutoCrop(); String customColor = request.getCustomColor(); float marginFactor; @@ -92,7 +93,7 @@ public ResponseEntity addStamp(@ModelAttribute AddStampRequest request) // Load the input PDF PDDocument document = Loader.loadPDF(pdfFile.getBytes()); - if ("pagingSeal".equalsIgnoreCase(stampType)){ + if (autoCrop && "image".equalsIgnoreCase(stampType)){ addPagingSeal( document, stampImage, diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java index 636c8db91fe..5b4673b0237 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java @@ -66,7 +66,10 @@ public class AddStampRequest extends PDFWithPageNums { @Schema(description = "The color for stamp", defaultValue = "#d3d3d3") private String customColor = "#d3d3d3"; - @Schema(description = "The percentage of the seal to the first page", example = "30") + @Schema(description = "Auto crop the image or not.", defaultValue = "false",example = "false") + private boolean autoCrop; + + @Schema(description = "The percentage of the seal to the first page", example = "20") private int firstPageRate; @Schema( diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index 3ed04805992..b2225d8c936 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -578,7 +578,7 @@ AddStampRequest.customMargin=Custom Margin AddStampRequest.customColor=Custom Text Color AddStampRequest.firstPageRate=First Page Rate AddStampRequest.submit=Submit - +AddStampRequest.autoCrop=Auto Crop( crops an image and evenly distributes it along the edges of every page ) #sanitizePDF sanitizePDF.title=Sanitize PDF @@ -948,7 +948,6 @@ watermark.selectText.9=Watermark Image: watermark.submit=Add Watermark watermark.type.1=Text watermark.type.2=Image -watermark.type.3=PagingSeal #Change permissions diff --git a/src/main/resources/messages_zh_CN.properties b/src/main/resources/messages_zh_CN.properties index 1a2223fa947..8867e1a7841 100644 --- a/src/main/resources/messages_zh_CN.properties +++ b/src/main/resources/messages_zh_CN.properties @@ -579,7 +579,7 @@ AddStampRequest.customMargin=自定义外边距 AddStampRequest.customColor=自定义文本颜色 AddStampRequest.firstPageRate=首页盖章比例 AddStampRequest.submit=提交 - +AddStampRequest.autoCrop=自动裁剪(骑缝章) #sanitizePDF sanitizePDF.title=清理PDF @@ -949,7 +949,6 @@ watermark.selectText.9=水印图片: watermark.submit=添加水印 watermark.type.1=文字 watermark.type.2=图片 -watermark.type.3=骑缝章 #Change permissions permissions.title=更改权限 diff --git a/src/main/resources/messages_zh_TW.properties b/src/main/resources/messages_zh_TW.properties index a04586646de..cde5346e371 100644 --- a/src/main/resources/messages_zh_TW.properties +++ b/src/main/resources/messages_zh_TW.properties @@ -579,7 +579,7 @@ AddStampRequest.customMargin=自訂邊緣 AddStampRequest.customColor=自訂文字顏色 AddStampRequest.firstPageRate=首页盖章比例 AddStampRequest.submit=送出 - +AddStampRequest.autoCrop=自動裁剪(騎縫章) #sanitizePDF sanitizePDF.title=清理 PDF @@ -949,7 +949,6 @@ watermark.selectText.9=浮水印影像: watermark.submit=新增浮水印 watermark.type.1=文字 watermark.type.2=圖片 -watermark.type.3=騎縫章 #Change permissions permissions.title=變更權限 diff --git a/src/main/resources/templates/misc/stamp.html b/src/main/resources/templates/misc/stamp.html index c1cf6bdd389..57e9b5c1537 100644 --- a/src/main/resources/templates/misc/stamp.html +++ b/src/main/resources/templates/misc/stamp.html @@ -62,10 +62,14 @@ +
+ + +
+
@@ -164,7 +168,7 @@
- +
@@ -176,13 +180,25 @@ const stampFormElementIds = ['pageOrderGroup','customMarginGroup','positionGroup', 'stampTextGroup', 'stampImageGroup', 'alphabetGroup', 'sizeGroup', 'rotationGroup', 'opacityGroup', 'overrideXGroup', 'overrideYGroup', 'customColorGroup','pagingPositionGroup', - 'FirstPageRateGroup']; + 'FirstPageRateGroup','autoCropGroups']; const stampFormElements = stampFormElementIds.map(it=>document.getElementById(it)); - + const autoCropGroupsElement = document.getElementById("autoCropGroups") + const autoCropElement = document.getElementById("autoCrop") // init function toggleFileOption(); bindSelectedPositionEvent(document.querySelectorAll('#positionGroup .pageNumber'), document.getElementById('numberInput')); bindSelectedPositionEvent(document.querySelectorAll('#pagingPositionGroup .pageNumber'),document.getElementById('pagingNumberInput')); + autoCropGroupsElement.addEventListener('click',function(){ + const allIds = ['pageOrderGroup','customMarginGroup','positionGroup','overrideXGroup', + 'pagingPositionGroup','FirstPageRateGroup'] + const allElements = allIds.map(it=>document.getElementById(it)); + if(autoCropElement.checked){ + showElementByIds(allElements,['pagingPositionGroup','FirstPageRateGroup']); + }else{ + showElementByIds(allElements,['pageOrderGroup','customMarginGroup','positionGroup','overrideXGroup']) + } + }) + function bindSelectedPositionEvent(cells,inputField){ cells.forEach(cell => { @@ -214,20 +230,23 @@ function toggleFileOption() { const stampType = document.getElementById('stampType').value; if (stampType === 'text') { - showElementByIds('pageOrderGroup','customMarginGroup','positionGroup','stampTextGroup', + showElementByIds(stampFormElements,['pageOrderGroup','customMarginGroup','positionGroup','stampTextGroup', 'alphabetGroup','sizeGroup','rotationGroup','opacityGroup','overrideXGroup', - 'overrideYGroup','customColorGroup' ) + 'overrideYGroup','customColorGroup'] ) } else if (stampType === 'image') { - showElementByIds('pageOrderGroup','customMarginGroup','positionGroup','stampImageGroup', - 'sizeGroup','rotationGroup','opacityGroup','overrideXGroup','overrideYGroup') - } else if (stampType === 'pagingSeal'){ - showElementByIds('stampImageGroup','pagingPositionGroup', 'sizeGroup','rotationGroup' - ,'opacityGroup','overrideYGroup','FirstPageRateGroup') + showElementByIds(stampFormElements,['pageOrderGroup','customMarginGroup','positionGroup','stampImageGroup', + 'sizeGroup','rotationGroup','opacityGroup','overrideXGroup','overrideYGroup','autoCropGroups']) + autoCropElement.checked = false } } - function showElementByIds(...showIds) { - stampFormElements.forEach(it=>{ + /** + * control element show or hidden + * @param formElements all elements id + * @param showIds The IDs that needs to be displayed. + */ + function showElementByIds(formElements,showIds) { + formElements.forEach(it=>{ const id = it.id; if(showIds && showIds.includes(id)){ it.style.display = 'block';