Compare commits

..
5 Commits
Author SHA1 Message Date
Reece BrowneandGitHub 12fff5b4a7 Merge branch 'main' into mac-print 2026-02-04 17:15:31 +00:00
ffd1abbdb3 Fix ClassCastException in extractBookmarks endpoint (#5578) (#5604)
## Description

Fixes #5578

This PR fixes a `ClassCastException` that occurs when calling
`/api/v1/general/extract-bookmarks`. The method was returning
`List<Map<String, Object>>` directly, but Spring MVC was wrapping it in
a `ResponseEntity`, causing a type mismatch.

## Changes

- Changed return type from `List<Map<String, Object>>` to
`ResponseEntity<List<Map<String, Object>>>`
- Wrapped return values with `ResponseEntity.ok(...)` to match Spring
MVC pattern
- Removed `@ResponseBody` annotation as it is not needed with
`ResponseEntity`

## Verification

This fix follows the same pattern used in other similar endpoints:
- `VerifyPDFController.verifyPDF()` returns
`ResponseEntity<List<PDFVerificationResult>>`
- `ValidateSignatureController.validateSignature()` returns
`ResponseEntity<List<SignatureValidationResult>>`

## Testing

The endpoint should now return a proper JSON response with the list of
bookmarks instead of throwing a 500 error.

---------

Co-authored-by: GitTensor Miner <miner@gittensor.io>
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2026-02-03 09:48:09 +00:00
79bc62a5d2 update to add optional Zero Padding to page numbers (Bates Stamping).… (#5612)
… 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

<!--
Another category is added to the add page number tool where it allows
for defining a 0 padded format. If left as 0, it will not added padded
0s and will be the current implementation.
-->

---

## 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>
2026-02-02 10:42:33 +00:00
Reece BrowneandGitHub 03da0e7d68 Merge branch 'main' into mac-print 2026-01-29 20:24:16 +00:00
Reece 685b562d3d Attempt to fix print on mac 2026-01-29 18:05:01 +00:00
10 changed files with 83 additions and 15 deletions
@@ -46,18 +46,18 @@ public class EditTableOfContentsController {
@Operation(
summary = "Extract PDF Bookmarks",
description = "Extracts bookmarks/table of contents from a PDF document as JSON.")
@ResponseBody
public List<Map<String, Object>> extractBookmarks(@RequestParam("file") MultipartFile file)
public ResponseEntity<List<Map<String, Object>>> extractBookmarks(@RequestParam("file") MultipartFile file)
throws Exception {
try (PDDocument document = pdfDocumentFactory.load(file)) {
PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();
if (outline == null) {
log.info("No outline/bookmarks found in PDF");
return new ArrayList<>();
return ResponseEntity.ok(new ArrayList<>());
}
return extractBookmarkItems(document, outline);
List<Map<String, Object>> bookmarks = extractBookmarkItems(document, outline);
return ResponseEntity.ok(bookmarks);
}
}
@@ -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}",
@@ -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,"
@@ -85,10 +85,12 @@ class EditTableOfContentsControllerTest {
when(mockOutlineItem.getNextSibling()).thenReturn(null);
// When
List<Map<String, Object>> result = editTableOfContentsController.extractBookmarks(mockFile);
ResponseEntity<List<Map<String, Object>>> response = editTableOfContentsController.extractBookmarks(mockFile);
// Then
assertNotNull(result);
assertNotNull(response);
assertNotNull(response.getBody());
List<Map<String, Object>> result = response.getBody();
assertEquals(1, result.size());
Map<String, Object> bookmark = result.get(0);
@@ -107,10 +109,12 @@ class EditTableOfContentsControllerTest {
when(mockCatalog.getDocumentOutline()).thenReturn(null);
// When
List<Map<String, Object>> result = editTableOfContentsController.extractBookmarks(mockFile);
ResponseEntity<List<Map<String, Object>>> response = editTableOfContentsController.extractBookmarks(mockFile);
// Then
assertNotNull(result);
assertNotNull(response);
assertNotNull(response.getBody());
List<Map<String, Object>> result = response.getBody();
assertTrue(result.isEmpty());
verify(mockDocument).close();
}
@@ -141,10 +145,12 @@ class EditTableOfContentsControllerTest {
when(childItem.getNextSibling()).thenReturn(null);
// When
List<Map<String, Object>> result = editTableOfContentsController.extractBookmarks(mockFile);
ResponseEntity<List<Map<String, Object>>> response = editTableOfContentsController.extractBookmarks(mockFile);
// Then
assertNotNull(result);
assertNotNull(response);
assertNotNull(response.getBody());
List<Map<String, Object>> result = response.getBody();
assertEquals(1, result.size());
Map<String, Object> parentBookmark = result.get(0);
@@ -177,10 +183,12 @@ class EditTableOfContentsControllerTest {
when(mockOutlineItem.getNextSibling()).thenReturn(null);
// When
List<Map<String, Object>> result = editTableOfContentsController.extractBookmarks(mockFile);
ResponseEntity<List<Map<String, Object>>> response = editTableOfContentsController.extractBookmarks(mockFile);
// Then
assertNotNull(result);
assertNotNull(response);
assertNotNull(response.getBody());
List<Map<String, Object>> result = response.getBody();
assertEquals(1, result.size());
Map<String, Object> bookmark = result.get(0);
@@ -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:"
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Enable printing capability -->
<key>com.apple.security.print</key>
<true/>
<!-- Enable network access for connecting to backend -->
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<!-- Enable file access for PDF handling -->
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<!-- Allow execution of bundled JRE -->
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
+2 -2
View File
@@ -5,7 +5,7 @@
"identifier": "stirling.pdf.dev",
"build": {
"frontendDist": "../dist",
"devUrl": "http://localhost:5173",
"devUrl": "http://localhost:5174",
"beforeDevCommand": "npm run dev -- --mode desktop",
"beforeBuildCommand": "npm run build -- --mode desktop"
},
@@ -67,7 +67,7 @@
"macOS": {
"minimumSystemVersion": "10.15",
"signingIdentity": null,
"entitlements": null,
"entitlements": "entitlements.plist",
"providerShortName": null
}
},
@@ -49,6 +49,16 @@ const AddPageNumbersAppearanceSettings = ({
/>
</Tooltip>
<Tooltip content={t('addPageNumbers.zeroPadTooltip', 'Zero-pad (Bates Stamp) page numbers to this width (e.g. 3 => 001). Set 0 to disable.')}>
<NumberInput
label={t('addPageNumbers.zeroPad', 'Zero-pad Width (Bates Stamping)')}
value={parameters.zeroPad}
onChange={(v) => onParameterChange('zeroPad', typeof v === 'number' ? v : 0)}
min={0}
disabled={disabled}
/>
</Tooltip>
<Tooltip content={t('fontTypeTooltip', 'Font family for the page numbers. Choose based on your document style.')}>
<Select
label={t('addPageNumbers.fontName', 'Font Type')}
@@ -13,6 +13,7 @@ export const buildAddPageNumbersFormData = (parameters: AddPageNumbersParameters
formData.append('startingNumber', String(parameters.startingNumber));
formData.append('pagesToNumber', parameters.pagesToNumber);
formData.append('customText', parameters.customText);
formData.append('zeroPad', String(parameters.zeroPad));
return formData;
};
@@ -9,6 +9,8 @@ export interface AddPageNumbersParameters extends BaseParameters {
startingNumber: number;
pagesToNumber: string;
customText: string;
// Number of digits to zero-pad page numbers to. 0 = no padding.
zeroPad: number;
}
export const defaultParameters: AddPageNumbersParameters = {
@@ -19,6 +21,7 @@ export const defaultParameters: AddPageNumbersParameters = {
startingNumber: 1,
pagesToNumber: '',
customText: '',
zeroPad: 0,
};
export type AddPageNumbersParametersHook = BaseParametersHook<AddPageNumbersParameters>;