# Description of Changes

<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
Anthony Stirling
2026-02-20 11:13:50 +00:00
committed by GitHub
parent 1ded9abb46
commit dcda01c2b9
7 changed files with 41 additions and 7 deletions

View File

@@ -194,7 +194,7 @@ public class PdfOverlayController {
// Load the overlay document to check its page count
try (PDDocument overlayPdf = Loader.loadPDF(overlayFile)) {
int overlayPageCount = overlayPdf.getNumberOfPages();
for (int j = 0; j < repeatCount; j++) {
for (int j = 0; j < repeatCount && currentPage <= basePageCount; j++) {
for (int page = 0; page < overlayPageCount; page++) {
if (currentPage > basePageCount) break;
overlayGuide.put(currentPage++, overlayFile.getAbsolutePath());

View File

@@ -191,6 +191,14 @@ public class RearrangePagesPDFController {
if (duplicateCount < 1) {
duplicateCount = 2; // Default to 2 if invalid input
}
int maxDuplicateCount = Math.max(100, totalPages * 3);
if (duplicateCount > maxDuplicateCount) {
throw ExceptionUtils.createIllegalArgumentException(
"error.invalidFormat",
"Invalid {0} format: {1}",
"duplicateCount",
"must not exceed " + maxDuplicateCount);
}
// For each page in the document
for (int pageNum = 0; pageNum < totalPages; pageNum++) {

View File

@@ -23,6 +23,8 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -57,7 +59,7 @@ public class SplitPdfBySectionsController {
+ " which page to split, and how to split"
+ " ( halves, thirds, quarters, etc.), both vertically and horizontally."
+ " Input:PDF Output:ZIP-PDF Type:SISO")
public ResponseEntity<byte[]> splitPdf(@ModelAttribute SplitPdfBySectionsRequest request)
public ResponseEntity<byte[]> splitPdf(@Valid @ModelAttribute SplitPdfBySectionsRequest request)
throws Exception {
MultipartFile file = request.getFileInput();
String pageNumbers = request.getPageNumbers();

View File

@@ -33,6 +33,8 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import stirling.software.SPDF.config.swagger.StandardPdfResponse;
@@ -71,7 +73,7 @@ public class WatermarkController {
"This endpoint adds a watermark to a given PDF file. Users can specify the"
+ " watermark type (text or image), rotation, opacity, width spacer, and"
+ " height spacer. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> addWatermark(@ModelAttribute AddWatermarkRequest request)
public ResponseEntity<byte[]> addWatermark(@Valid @ModelAttribute AddWatermarkRequest request)
throws IOException, Exception {
MultipartFile pdfFile = request.getFileInput();
String pdfFileName = pdfFile.getOriginalFilename();
@@ -237,8 +239,8 @@ public class WatermarkController {
// Calculating the number of rows and columns.
int watermarkRows = (int) (pageHeight / newWatermarkHeight + 1);
int watermarkCols = (int) (pageWidth / newWatermarkWidth + 1);
int watermarkRows = Math.min((int) (pageHeight / newWatermarkHeight + 1), 10_000);
int watermarkCols = Math.min((int) (pageWidth / newWatermarkWidth + 1), 10_000);
// Add the text watermark
for (int i = 0; i <= watermarkRows; i++) {
@@ -290,9 +292,13 @@ public class WatermarkController {
float pageWidth = page.getMediaBox().getWidth();
float pageHeight = page.getMediaBox().getHeight();
int watermarkRows =
(int) ((pageHeight + heightSpacer) / (desiredPhysicalHeight + heightSpacer));
Math.min(
(int) ((pageHeight + heightSpacer) / (desiredPhysicalHeight + heightSpacer)),
10_000);
int watermarkCols =
(int) ((pageWidth + widthSpacer) / (desiredPhysicalWidth + widthSpacer));
Math.min(
(int) ((pageWidth + widthSpacer) / (desiredPhysicalWidth + widthSpacer)),
10_000);
for (int i = 0; i < watermarkRows; i++) {
for (int j = 0; j < watermarkCols; j++) {

View File

@@ -2,6 +2,9 @@ package stirling.software.SPDF.model.api;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -33,6 +36,8 @@ public class SplitPdfBySectionsRequest extends PDFFile {
defaultValue = "0",
minimum = "0",
requiredMode = Schema.RequiredMode.REQUIRED)
@Min(value = 0, message = "Horizontal divisions must be non-negative")
@Max(value = 50, message = "Horizontal divisions must not exceed 50")
private int horizontalDivisions;
@Schema(
@@ -40,6 +45,8 @@ public class SplitPdfBySectionsRequest extends PDFFile {
defaultValue = "1",
minimum = "0",
requiredMode = Schema.RequiredMode.REQUIRED)
@Min(value = 0, message = "Vertical divisions must be non-negative")
@Max(value = 50, message = "Vertical divisions must not exceed 50")
private int verticalDivisions;
@Schema(

View File

@@ -4,6 +4,9 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Min;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -32,6 +35,7 @@ public class AddWatermarkRequest extends PDFFile {
private String alphabet;
@Schema(description = "The font size of the watermark text", defaultValue = "30")
@DecimalMin(value = "1.0", message = "Font size must be at least 1.0")
private float fontSize;
@Schema(description = "The rotation of the watermark in degrees", defaultValue = "0")
@@ -41,9 +45,11 @@ public class AddWatermarkRequest extends PDFFile {
private float opacity;
@Schema(description = "The width spacer between watermark elements", defaultValue = "50")
@Min(value = 0, message = "Width spacer must be non-negative")
private int widthSpacer;
@Schema(description = "The height spacer between watermark elements", defaultValue = "50")
@Min(value = 0, message = "Height spacer must be non-negative")
private int heightSpacer;
@Schema(description = "The color for watermark", defaultValue = "#d3d3d3")