[V2] feat(redaction): implement PDFium-based redaction service and CLI tool - #5183
[V2] feat(redaction): implement PDFium-based redaction service and CLI tool#5183balazs-szucs wants to merge 7 commits into
Conversation
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces PDFium-based redaction capabilities to enhance PDF text removal accuracy, refactors text search logic for better performance, and updates API models. The implementation adds a Node.js CLI tool that interfaces with PDFium's WASM binary, a new Java service to manage PDFium processes, and modernizes the redaction controller to use parallel processing with retry logic for handling text reflow in tables.
Key Changes:
- Added PDFium integration with Node.js CLI tool (
redact.cjs) and Java service (PdfiumRedactionService) for native PDF text removal - Refactored
TextFinderclass to extract pattern building and bounds calculation into dedicated helper methods/classes, added font size tracking toPDFTextmodel - Updated
RedactControllerto implement parallel text searching, PDFium-first redaction with fallback to PDFBox overlays, and retry logic for stubborn text matches
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/scripts/pdfium/redact.cjs | New Node.js CLI tool for PDFium-based redaction with WASM integration |
| frontend/eslint.config.mjs | Added .cjs extension to ESLint configuration for new script |
| RedactControllerTest.java | Extensive test updates including PDFium mocking, parallel processing tests, removed content stream tests |
| WidthCalculator.java | Deleted - width calculation logic no longer needed with PDFium approach |
| TextFinderUtils.java | Deleted - pattern creation moved to TextFinder |
| TextEncodingHelper.java | Deleted - encoding validation no longer required with PDFium |
| PdfiumRedactionService.java | New service managing PDFium environment, process execution, and coordinate conversion |
| TextFinder.java | Refactored to extract pattern/bounds logic into helper classes, added font size tracking |
| RedactPdfRequest.java | Updated API documentation and changed default for convertPDFToImage to true |
| PdfiumRedactionRegion.java | New value class representing PDFium redaction regions |
| PDFText.java | Added fontSize field for improved bounding calculations |
| RedactController.java | Major refactor: parallel processing, PDFium integration, retry logic, page rotation handling |
| InitialSetup.java | Minor whitespace cleanup |
| ProcessExecutor.java | Added PDFIUM_REDACTOR process type with session limits and timeout configuration |
| ApplicationProperties.java | Added configuration properties for PDFium redactor session limits and timeouts |
Comments suppressed due to low confidence (1)
app/core/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java:82
- The method 'redactPDF' may be confused with redactPdf.
public ResponseEntity<byte[]> redactPDF(@ModelAttribute ManualRedactPdfRequest request)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
# Conflicts: # app/common/src/main/java/stirling/software/common/model/ApplicationProperties.java # app/common/src/main/java/stirling/software/common/util/ProcessExecutor.java # app/core/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java # app/core/src/main/java/stirling/software/SPDF/pdf/TextFinder.java # app/core/src/main/java/stirling/software/SPDF/utils/text/TextEncodingHelper.java # app/core/src/test/java/stirling/software/SPDF/controller/api/security/RedactControllerTest.java
…umRedactor and ffmpeg Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…mments in PDFium region calculation Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
|
On hold due to embedPDF V2 |
|
Sorry to be bugging you again, is this the continuation of #4240? |
|
already done? |
Description of Changes
This pull request introduces support for PDF redaction using PDFium, refines the text search and bounding logic in the
TextFinderclass, and updates configuration and API models to accommodate these changes. The main themes are: enabling PDFium-based redaction (including configuration and process management), improving text search accuracy, and updating related API models.PDFium Redactor Integration and Configuration:
PDFIUM_REDACTORas a newProcessesenum value and integrated it into the process execution logic, including session limit and timeout retrieval inProcessExecutorand corresponding properties inApplicationProperties.PdfiumRedactionRegionto represent redaction regions for PDFium-based redaction.Text Search and Bounding Improvements:
TextFinderclass: extracted search pattern construction and bounding box calculation into helper methods and classes, improved fallback logic for missing position data, and enhanced debug logging. ThePDFTextmodel now includesfontSize.API Model and Defaults Updates:
RedactPdfRequest: clarified the description and default value forlistOfText, and changed the default forconvertPDFToImagetotrue.These changes collectively enable robust PDF redaction capabilities using PDFium, improve the accuracy of text search and bounding, and ensure the API and configuration are up to date with these enhancements.
Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)