Adding redaction annotations to a PDF document
Redaction annotations in Nutrient Java SDK
Redaction annotations enable teams to permanently remove sensitive content and comply with privacy regulations such as General Data Protection Regulation (GDPR) or Health Insurance Portability and Accountability Act (HIPAA). This process protects confidential information before document distribution in legal, government, financial, and HR workflows.
Redaction annotation operations
Redaction involves the following steps:
- Marking — Define rectangular areas for removal with visual indicators.
- Customization — Configure overlay colors and patterns for the redacted area.
- Execution — Permanently delete underlying text and images.
- Verification — Ensure redacted content is unrecoverable after application.
This guide demonstrates how to add redaction annotations and apply them to remove sensitive data. Adding an annotation marks an area for removal, but the content remains until you apply the redaction. Once applied, the SDK permanently deletes the underlying information.
How Nutrient helps you achieve this
Nutrient Java SDK manages PDF annotations, redaction marking, and permanent content removal. The SDK handles the following technical requirements:
- Annotation management — Managing PDF structures, appearance streams, and coordinate transformations.
- Redaction logic — Removing underlying content while preserving document structure.
- Visual customization — Handling color space conversions and appearance settings for redaction overlays.
- Save coordination — Managing preferences for automatic redaction application versus annotation preservation.
Nutrient provides an API that manages these complexities, enabling you to focus on your business logic.
Complete implementation
The example below demonstrates how to add redaction annotations to PDF documents for permanent content removal.
Packaging and imports
Start by specifying the package name and importing the required classes. These imports enable document handling, color customization, and redaction management:
package io.nutrient.Sample;
import io.nutrient.sdk.Document;import io.nutrient.sdk.types.Color;import io.nutrient.sdk.editors.PdfEditor;import io.nutrient.sdk.editors.pdf.pages.PdfPageCollection;import io.nutrient.sdk.editors.pdf.pages.PdfPage;import io.nutrient.sdk.editors.pdf.annotations.PdfAnnotationCollection;import io.nutrient.sdk.editors.pdf.annotations.PdfRedactAnnotation;import io.nutrient.sdk.enums.PdfSavePreferences;import io.nutrient.sdk.settings.PdfSettings;
public class RedactionAnnotations {Main entry point
Create the main class and function to contain the redaction logic:
public static void main(String[] args) {Initializing the editor and page
Open a PDF document using a try-with-resources statement to ensure the SDK releases memory and data after processing. This block creates a PdfEditor instance and accesses the page collection. If the document is empty, the code adds a blank US Letter page (612 × 792 points):
try (Document document = Document.open("input.pdf")) { PdfEditor editor = PdfEditor.edit(document); PdfPageCollection pages = editor.getPageCollection();
if (pages.getCount() == 0) { pages.add(612.0f, 792.0f); }
PdfPage page = pages.getFirst(); PdfAnnotationCollection annotations = page.getAnnotationCollection();Adding a redaction annotation
Mark a rectangular area for content removal. The PDF coordinate system uses points (1 inch equals 72 points) with the origin at the bottom-left corner. This example targets the top area of the page:
PdfRedactAnnotation redaction = annotations.addRedact( 72.0f, 684.0f, 504.0f, 72.0f // x, y, width, height (1 inch from left, 9.5 inches from bottom, 7 inches wide, 1 inch tall) );Customizing the redaction appearance
Define the visual appearance of the redacted area. The interior color determines what’s visible after you apply the redaction. Setting this color to opaque black permanently obscures the underlying content:
redaction.setInteriorColor(Color.fromArgb(255, 0, 0, 0));Configuring save preferences
Control whether the SDK applies redactions automatically during save operations. By default, the SDK removes sensitive content immediately upon saving. To preserve annotations for a review workflow, set PdfSavePreferences to None. This enables stakeholders to verify marks before permanent deletion:
document.getSettings().getPdfSettings().setSavePreferences(PdfSavePreferences.None);Saving the document
Save the modified document to a new file and close the editor. The catch block handles any exceptions that occur during document processing:
editor.saveAs("output.pdf"); editor.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); } }}Conclusion
The redaction annotation workflow involves these steps:
- Initialize the document — Open the PDF using a try-with-resources statement for automatic resource cleanup.
- Access the editor — Create a
PdfEditorinstance to manage pages and annotations. - Prepare the page — Retrieve the page collection and verify the document contains pages; add a blank page if it’s empty.
- Target the page — Use zero-based indexing to retrieve the specific page for redaction.
- Access annotations — Retrieve the annotation collection from the target page.
- Create the mark — Add a redaction annotation by specifying the x, y, width, and height in points.
- Define coordinates — Use the PDF coordinate system (72 points per inch) where the origin (0, 0) is at the bottom-left corner.
- Set appearance — Use
setInteriorColor()with ARGB values to define the fill color that covers the removed content. - Configure application — Set save preferences to control whether the SDK applies redactions immediately or preserves them for review.
- Finalize — Save the document and close the editor while handling any processing exceptions.
Nutrient manages PDF structures, appearance streams, and coordinate transformations, so you don’t need to implement complex redaction algorithms manually. This system ensures permanent content removal and regulatory compliance across legal, financial, and government workflows.