From 79bc62a5d24edd701d403ab54fdd9a623c152ed3 Mon Sep 17 00:00:00 2001 From: mrober01 Date: Mon, 2 Feb 2026 02:42:33 -0800 Subject: [PATCH] =?UTF-8?q?update=20to=20add=20optional=20Zero=20Padding?= =?UTF-8?q?=20to=20page=20numbers=20(Bates=20Stamping).=E2=80=A6=20(#5612)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … Useful in legal and other professional fields to have page numbers written with padded 0s of a fixed width. This is also known as bates stamping. # Description of Changes --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [x] 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) - [x] I have performed a self-review of my own code - [x] 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) - [x] 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. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> --- .../controller/api/misc/PageNumbersController.java | 11 ++++++++++- .../SPDF/model/api/misc/AddPageNumbersRequest.java | 7 +++++++ frontend/public/locales/en-GB/translation.toml | 3 +++ .../AddPageNumbersAppearanceSettings.tsx | 10 ++++++++++ .../addPageNumbers/useAddPageNumbersOperation.ts | 1 + .../addPageNumbers/useAddPageNumbersParameters.ts | 3 +++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java index 41cbe7328..6d0d05a28 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/misc/PageNumbersController.java @@ -52,9 +52,17 @@ public class PageNumbersController { int pageNumber = request.getStartingNumber(); String pagesToNumber = request.getPagesToNumber(); String customText = request.getCustomText(); + int zeroPad = request.getZeroPad(); float fontSize = request.getFontSize(); String fontType = request.getFontType(); String fontColor = request.getFontColor(); + // compute padded number string where requested + String formatN; + if (zeroPad > 0) { + formatN = String.format("%%0%dd", Math.max(0, zeroPad)); + } else { + formatN = "%d"; + } Color color = Color.BLACK; if (fontColor != null && !fontColor.trim().isEmpty()) { @@ -93,9 +101,10 @@ public class PageNumbersController { PDPage page = document.getPage(i); PDRectangle pageSize = page.getMediaBox(); + String nFormatted = String.format(formatN, pageNumber); String text = customText - .replace("{n}", String.valueOf(pageNumber)) + .replace("{n}", nFormatted) .replace("{total}", String.valueOf(document.getNumberOfPages())) .replace( "{filename}", diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java index 3e116742d..c4b907465 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/misc/AddPageNumbersRequest.java @@ -39,6 +39,13 @@ public class AddPageNumbersRequest extends PDFWithPageNums { requiredMode = RequiredMode.NOT_REQUIRED) private String fontColor; + @Schema( + description = "Zero-padding width for page numbers (Bates Stamping). Set to 0 to disable padding", + minimum = "0", + defaultValue = "0", + requiredMode = RequiredMode.NOT_REQUIRED) + private int zeroPad = 0; + @Schema( description = "Position: 1-9 representing positions on the page (1=top-left, 2=top-center," diff --git a/frontend/public/locales/en-GB/translation.toml b/frontend/public/locales/en-GB/translation.toml index 2bb1b12f9..a0077e184 100644 --- a/frontend/public/locales/en-GB/translation.toml +++ b/frontend/public/locales/en-GB/translation.toml @@ -219,6 +219,9 @@ pagesAndStarting = "Pages & Starting Number" positionAndPages = "Position & Pages" preview = "Position Selection" previewDisclaimer = "Preview is approximate. Final output may vary due to PDF font metrics." +zeroPad = "Zero‑pad Width (Bates Stamping)" +zeroPadTooltip = "Zero‑pad (Bates Stamp) page numbers to this width (e.g., 3 ⇒ 001). Set 0 to disable." + [addPageNumbers.selectText] 1 = "Select PDF file:" diff --git a/frontend/src/core/components/tools/addPageNumbers/AddPageNumbersAppearanceSettings.tsx b/frontend/src/core/components/tools/addPageNumbers/AddPageNumbersAppearanceSettings.tsx index 6ff03ede6..0ff9690d8 100644 --- a/frontend/src/core/components/tools/addPageNumbers/AddPageNumbersAppearanceSettings.tsx +++ b/frontend/src/core/components/tools/addPageNumbers/AddPageNumbersAppearanceSettings.tsx @@ -49,6 +49,16 @@ const AddPageNumbersAppearanceSettings = ({ /> + 001). Set 0 to disable.')}> + onParameterChange('zeroPad', typeof v === 'number' ? v : 0)} + min={0} + disabled={disabled} + /> + +