Skip to content

[V2] feat(redaction): implement PDFium-based redaction service and CLI tool - #5183

Closed
balazs-szucs wants to merge 7 commits into
Stirling-Tools:mainfrom
balazs-szucs:redact-V2-rework
Closed

[V2] feat(redaction): implement PDFium-based redaction service and CLI tool#5183
balazs-szucs wants to merge 7 commits into
Stirling-Tools:mainfrom
balazs-szucs:redact-V2-rework

Conversation

@balazs-szucs

Copy link
Copy Markdown
Collaborator

Description of Changes

This pull request introduces support for PDF redaction using PDFium, refines the text search and bounding logic in the TextFinder class, 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:

  • Added PDFIUM_REDACTOR as a new Processes enum value and integrated it into the process execution logic, including session limit and timeout retrieval in ProcessExecutor and corresponding properties in ApplicationProperties.
  • Introduced a new value class PdfiumRedactionRegion to represent redaction regions for PDFium-based redaction.

Text Search and Bounding Improvements:

  • Refactored the TextFinder class: extracted search pattern construction and bounding box calculation into helper methods and classes, improved fallback logic for missing position data, and enhanced debug logging. The PDFText model now includes fontSize.

API Model and Defaults Updates:

  • Updated RedactPdfRequest: clarified the description and default value for listOfText, and changed the default for convertPDFToImage to true.

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)

  • 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 for more details.

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
Copilot AI review requested due to automatic review settings December 7, 2025 20:30
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines ignoring generated files. enhancement New feature or request labels Dec 7, 2025
@stirlingbot stirlingbot Bot added Java Pull requests that update Java code Back End Issues related to back-end development API API-related issues or pull requests Test Testing-related issues or pull requests labels Dec 7, 2025
@balazs-szucs
balazs-szucs marked this pull request as draft December 7, 2025 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TextFinder class to extract pattern building and bounds calculation into dedicated helper methods/classes, added font size tracking to PDFText model
  • Updated RedactController to 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.

Comment thread frontend/scripts/pdfium/redact.cjs
@balazs-szucs
balazs-szucs marked this pull request as ready for review December 7, 2025 20:45
@balazs-szucs balazs-szucs changed the title feat(redaction): implement PDFium-based redaction service and CLI tool [V2] feat(redaction): implement PDFium-based redaction service and CLI tool Dec 10, 2025
@stirlingbot stirlingbot Bot removed the enhancement New feature or request label Dec 10, 2025
# 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>
@balazs-szucs
balazs-szucs marked this pull request as draft December 24, 2025 14:38
…mments in PDFium region calculation

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
@balazs-szucs

Copy link
Copy Markdown
Collaborator Author

On hold due to embedPDF V2

@christaikobo

Copy link
Copy Markdown

Sorry to be bugging you again, is this the continuation of #4240?

@stirlingbot stirlingbot Bot added the has conflicts Pull request has merge conflicts with the base branch label Jul 21, 2026
@Frooodle

Copy link
Copy Markdown
Member

already done?

@Frooodle Frooodle closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API-related issues or pull requests Back End Issues related to back-end development has conflicts Pull request has merge conflicts with the base branch Java Pull requests that update Java code size:XXL This PR changes 1000+ lines ignoring generated files. Test Testing-related issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants