How to add suffix to filename in GroupDocs redaction Java
In this groupdocs redaction java tutorial you’ll learn how to automatically append a suffix to the output file name when redacting documents with GroupDocs.Redaction. Adding a suffix eliminates manual renaming, reduces the risk of leaking unredacted files, and fits neatly into CI/CD pipelines that rely on naming conventions. The guide walks you through Maven setup, streaming document loading, annotation removal, and configuring save options—all with concise, production‑ready code.
Quick answers
- What does “add suffix to filename” do?
When you enable the suffix option, the SDK automatically appends a predefined string (by default “_redacted”) to the base name of the output file before the extension. This makes it immediately clear which files have been processed, helps prevent accidental distribution of original content, and simplifies downstream automation that relies on naming patterns. - Can I load a document from stream?
Yes—GroupDocs.Redaction supports loading from anyInputStream, perfect for cloud storage or in‑memory processing. - Do I need a license for this feature?
A free trial works for basic redaction; a temporary or full license unlocks all advanced options, including suffix handling. - Which formats are supported?
The library handles DOCX, PDF, PPTX, XLSX and many more. - Is rasterization required for PDF output?
Rasterization is optional; enable it when you need to flatten the document for extra security.
What does “add suffix to filename” do?
When you enable the suffix option, the SDK automatically appends a predefined string (by default “_redacted”) to the base name of the output file before the extension. This makes it immediately clear which files have been processed, helps prevent accidental distribution of original content, and simplifies downstream automation that relies on naming patterns.
Why use GroupDocs.Redaction for this task?
GroupDocs.Redaction offers a high‑performance Java API that combines redaction actions with flexible file‑handling options such as automatic suffix addition, streaming support, and batch processing. It supports over 50 input and output formats and can process multi‑hundred‑page documents without loading the entire file into memory, ensuring low memory usage and fast execution.
Prerequisites
- Java Development Kit (JDK): Version 8 or higher.
- GroupDocs.Redaction Library: Core library for redaction tasks.
- IDE: IntelliJ IDEA, Eclipse, or any Java‑compatible editor.
- Maven: For dependency management.
Knowledge prerequisites
Familiarity with Java I/O and basic object‑oriented concepts will make the examples easier to follow.
Setting up GroupDocs.Redaction for Java
Maven setup
Include the following configuration in your pom.xml file to access GroupDocs libraries via Maven:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/redaction/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-redaction</artifactId>
<version>24.9</version>
</dependency>
</dependencies>
Direct download
Alternatively, download the latest version directly from GroupDocs.Redaction for Java releases.
License acquisition
- Free trial: Access basic functionality without restrictions.
- Temporary license: Obtain a temporary license to explore advanced features.
- Purchase: For long‑term use, consider purchasing a full license.
Basic initialization and setup
Initialize your project by adding the necessary imports:
import com.groupdocs.redaction.Redactor;
With this setup, you’re ready to implement document redaction functionalities.
Implementation guide
Feature 1: load document from stream
Overview: Learn how to load documents into an InputStream for processing.
InputStream is a Java I/O class that represents a stream of bytes, allowing you to read data from files, network connections, or other sources without loading the entire content into memory.
Step 1.1: create inputstream
import java.io.FileInputStream;
import java.io.InputStream;
try (InputStream stream = new FileInputStream("YOUR_DOCUMENT_DIRECTORY/SAMPLE_DOCX")) {
final Redactor redactor = new Redactor(stream);
try {
// Document is now loaded and ready for further processing
} finally {
redactor.close();
}
}
- Why: Using
InputStreamallows you to handle documents stored in various locations—cloud buckets, databases, or in‑memory buffers—without first writing them to disk. This approach is essential when you need to load document from stream in micro‑service architectures.
Feature 2: apply annotation deletion redaction
Overview: Remove annotations from your document using the DeleteAnnotationRedaction.
DeleteAnnotationRedaction is a redaction operation that removes all annotations—such as comments, highlights, and notes—from the document.
Step 2.1: apply deleteannotationredaction
import com.groupdocs.redaction.redactions.DeleteAnnotationRedaction;
try (Redactor redactor = new Redactor("YOUR_DOCUMENT_DIRECTORY/SAMPLE_DOCX")) {
// Apply the DeleteAnnotationRedaction to remove annotations from the document
redactor.apply(new DeleteAnnotationRedaction());
}
- Why: This step ensures that any sensitive annotations (comments, highlights, or hidden notes) are stripped from the document, enhancing privacy and compliance.
Feature 3: save document with options
Overview: Learn how to save your processed document with specific options like rasterization and add suffix filename java.
SaveOptions encapsulates settings that control how the redacted document is written, including format, rasterization, and naming conventions.
Step 3.1: configure saveoptions
import java.io.ByteArrayOutputStream;
import com.groupdocs.redaction.options.SaveOptions;
try (Redactor redactor = new Redactor("YOUR_DOCUMENT_DIRECTORY/SAMPLE_DOCX")) {
// Apply necessary redactions before saving
redactor.apply(new DeleteAnnotationRedaction());
try (ByteArrayOutputStream bA = new ByteArrayOutputStream()) {
SaveOptions options = new SaveOptions();
options.setRasterizeToPDF(true); // Option to rasterize document to PDF format
options.setAddSuffix(true); // Option to add a suffix to the saved file name
redactor.save(bA, options.getRasterization());
}
}
- Why: Customizing save options allows flexible output formats and naming conventions. Enabling
setAddSuffix(true)adds suffix to filename, making it clear that the file has been redacted.
How to add suffix filename java when saving a document?
The Redactor class is the core component that loads a document and applies redaction operations. SaveOptions defines how the redacted document is saved, including format, rasterization, and naming conventions. Create a Redactor instance, apply any required redactions, then configure a SaveOptions object with setAddSuffix(true). Call redactor.save(outputPath, options). The SDK automatically appends “_redacted” (or the configured suffix) to the file name, so you never need to rename the file manually.
GroupDocs Maven dependency overview
The groupdocs maven dependency brings the entire Redaction SDK into your project with a single <dependency> entry. It handles transitive dependencies, keeps libraries up‑to‑date, and simplifies build automation. By declaring the dependency in pom.xml, you avoid manual JAR management and ensure compatibility with the latest security patches.
Why adding a suffix matters
Appending a suffix provides immediate visual confirmation that a file has been processed, which is critical for audit trails, automated workflows, and regulatory compliance. It lets scripts filter redacted files, prevents accidental distribution of original content, and satisfies many industry standards that require clear labeling of sanitized documents.
Practical applications
Explore these real‑world use cases:
- Legal document redaction: Secure contracts before client sharing.
- Medical record handling: Protect patient identifiers while preserving clinical data.
- Financial reporting: Keep sensitive numbers confidential during external audits.
- CRM integration: Automatically redact customer data before export to third‑party tools.
- Collaboration tools: Ensure shared drafts never expose hidden comments or metadata.
Performance considerations
Optimizing performance
- Use streaming (
load document from stream) to avoid loading whole files into memory. - Close
Redactorinstances promptly to free resources.
Resource usage guidelines
- Monitor CPU and memory during batch runs.
- Prefer
ByteArrayOutputStreamfor in‑memory saves when working with modest file sizes.
Best practices for Java memory management
- Reuse
Redactorobjects when processing multiple files of the same type. - Invoke
close()in atry‑with‑resourcesblock to prevent leaks.
Common issues and solutions
| Issue | Cause | Fix |
|---|---|---|
| Suffix not appearing | setAddSuffix(false) or missing call | Ensure options.setAddSuffix(true) is set before save(). |
| OutOfMemoryError on large DOCX | Loading whole file into memory | Switch to InputStream loading (see Feature 1). |
| Annotations still visible | Redaction not applied before save | Call redactor.apply(new DeleteAnnotationRedaction()) before save(). |
| PDF rasterization not applied | setRasterizeToPDF(false) or omitted | Set options.setRasterizeToPDF(true) when you need a flattened PDF. |
Frequently asked questions
Q: Can I redact PDF documents using GroupDocs.Redaction?
A: Yes, the library supports PDFs, DOCX, PPTX, XLSX, and many other formats.
Q: What is the best way to handle large files with GroupDocs.Redaction?
A: Use streaming (load document from stream) and close resources promptly to keep memory usage low.
Q: Is it possible to customize the suffix text?
A: The API automatically adds a default suffix (e.g., “_redacted”). For custom suffixes, rename the output file after saving.
Q: How do I obtain a temporary license for GroupDocs.Redaction?
A: Visit the Temporary License page and follow the instructions.
Q: Where can I get help if I encounter issues?
A: Join the GroupDocs Support Forum for expert assistance.
Resources
- Documentation: Explore detailed guides at GroupDocs Documentation.
- API reference: Access comprehensive API details on GroupDocs API Reference.
- Download: Get the latest version from GroupDocs Downloads.
- GitHub repository: Contribute or explore source code at GroupDocs GitHub.
Last Updated: 2026-11-02
Tested With: GroupDocs.Redaction 24.9 for Java
Author: GroupDocs