Adding redaction annotations to a PDF document
Use redaction annotations to remove sensitive PDF content before distribution.
Common use cases include:
- Privacy and compliance workflows (for example GDPR and HIPAA)
- Legal and government document release
- Financial and HR document sanitization
- Internal review before external sharing
Redaction annotation operations
Redaction involves the following steps:
- Marking — Define rectangular areas for removal.
- Customization — Configure redaction overlay appearance.
- Execution — Permanently delete underlying content.
- Verification — Confirm removed content isn’t recoverable.
Adding an annotation only marks content for removal. Sensitive content remains until redactions are applied.
How Nutrient helps
Nutrient Java SDK handles redaction marking and content removal.
The SDK handles:
- PDF annotation structures and coordinate handling
- Redaction content removal behavior
- Overlay appearance and color configuration
- Save behavior for apply-now vs. review-first workflows
Complete implementation
This example adds redaction annotations and configures save behavior.
Packaging and imports
Specify the package name and import the required classes:
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 method as the sample entry point:
public static void main(String[] args) {Initializing the editor and page
Open the document with try-with-resources, create an editor, and ensure a page exists:
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 = 72 points), with the origin at the bottom-left corner:
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
Set the redaction fill color. This color appears after the redaction is applied:
redaction.setInteriorColor(Color.fromArgb(255, 0, 0, 0));Configuring save preferences
Control when redactions are applied during save.
Set PdfSavePreferences.None to preserve annotations for review before permanent removal:
document.getSettings().getPdfSettings().setSavePreferences(PdfSavePreferences.None);Saving the document
Save the output and close the editor:
editor.saveAs("output.pdf"); editor.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); } }}Conclusion
Use this workflow to add redaction annotations:
- Open the document with try-with-resources.
- Create a
PdfEditorand access the target page. - Add redaction annotations with position and size in points.
- Set redaction appearance with
setInteriorColor(). - Configure save preferences for review-first or apply-now behavior.
- Save the document and close the editor.
For related document workflows, refer to the Java SDK guides.