You can use GroupDocs.Redaction for Java to redact text from a PDF in a Linux Docker container. This tutorial shows how to create a Maven console application, find an exact phrase, cover it with a black box, and run the application in Docker. The same approach can be used with other supported document formats.
Create a Java console project with Docker support
Create a Maven project that targets JDK 8 or later (JDK 17 LTS is recommended).
The package provides the Redactor class for loading and processing documents, along with the classes and options needed to find and redact sensitive content.
Add the PDF file
Place the PDF you want to process in the project directory and name it document.pdf. The application searches this file for the target phrase and creates document_Redacted.pdf with the redacted content. In this example, the PDF contains the word gap.
Add the redaction code
Replace the contents of App.java with the following code:
apply returns the redaction status. Check this status before treating the output as successfully redacted. save can still create an output file if the redaction was not applied.
Configure the Dockerfile
The following Dockerfile installs the Linux libraries and fonts commonly required for document processing, builds the Maven project, and runs the application.
Ensure pom.xml builds an executable JAR (for example with the Maven Shade Plugin or Spring Boot packaging), or adjust the ENTRYPOINT to run java -cp ... com.example.App with the GroupDocs dependency on the classpath.
Build the application image
From the project directory:
docker build -t PdfRedactionDocker .
Run the container
Mount the project directory into the container and run the application:
docker run --rm \
-v "${PWD}:/data"\
-w /data \
PdfRedactionDocker
The project directory is mounted at /data and used as the working directory. The application reads /data/document.pdf and writes /data/document_Redacted.pdf. Because /data is mapped to the project directory on the host, the redacted PDF appears next to the source file.
On Windows PowerShell, ${PWD} expands to the current directory. Run the command from the project directory.
Check the redacted PDF
Open document_Redacted.pdf. The specified phrase should be covered by a black rectangle, while the original document.pdf remains unchanged.
You can redact text and other sensitive content in PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, email files, and more with our free online Free Online Document Redaction App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Ask AI
Ask anything about this page — the answer is based on its content.
Searching the docs and writing an answer…
Something went wrong while getting an answer. Please try again in a moment.