Redaction annotations

Redaction annotations permanently remove sensitive content to ensure compliance with privacy regulations. This process involves two stages: marking areas for removal, and applying the redactions to delete the underlying data.

Redaction workflow

  1. Marking — Create redaction annotations to define areas for removal. These act as placeholders you can review.
  2. Application — Apply the annotations to permanently delete text and images. Once you apply a redaction, the content is unrecoverable.

Use cases

  • Legal and government — Remove case-sensitive or classified information before public release.
  • Healthcare and finance — Redact PII, Social Security numbers, and account details to meet Health Insurance Portability and Accountability Act (HIPAA) or General Data Protection Regulation (GDPR) requirements.
  • Human resources — Mask confidential data, such as salaries, within employment contracts.

Capabilities

  • Define rectangular areas for content removal.
  • Customize the appearance using overlay colors or patterns.
  • Enable manual or automatic redaction during save operations.
  • Ensure data is unrecoverable after application.

How Nutrient helps you achieve this

Nutrient Python SDK manages the underlying complexities of PDF redaction, including:

  • Annotation architecture — Handles appearance streams, coordinate transformations, and PDF structures.
  • Content removal logic — Deletes underlying data while maintaining document integrity.
  • Visual customization — Manages color space conversions and overlay patterns.
  • Save automation — Controls whether to apply redactions or preserve markers during save operations.

The SDK’s API abstracts these tasks, enabling you to focus on your application’s business logic.

Complete implementation

The example below demonstrates how to add and customize redaction annotations using Nutrient Python SDK.

Imports

Import the classes required for document handling, editing, and customization:

from nutrient_sdk import Document
from nutrient_sdk import PdfEditor
from nutrient_sdk import Color
from nutrient_sdk import NutrientException
from nutrient_sdk import PdfSavePreferences
from nutrient_sdk import PdfSettings

Setting up and page access

Open the PDF using a context manager(opens in a new tab) to ensure proper resource cleanup. If the document is empty, add a standard US Letter page (612 × 792 points):

def main():
try:
with Document.open("input.pdf") as document:
editor = PdfEditor.edit(document)
pages = editor.get_page_collection()
if pages.get_count() == 0:
pages.add(612.0, 792.0)
page = pages.get_first()
annotations = page.get_annotation_collection()

Adding a redaction annotation

Define the area for content removal. The coordinate system uses points (1 inch = 72 points), starting from the bottom-left corner. This example marks the header area:

redaction = annotations.add_redact(
72.0, 684.0, 504.0, 72.0 # 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 interior_color to determine the fill color applied to the area after the content is deleted:

redaction.interior_color = Color.from_argb(255, 0, 0, 0)

Configuring save preferences

By default, the SDK applies redactions automatically during save. To preserve the markers for review without deleting the underlying content, set the save preference to NONE:

document.settings.pdf_settings.save_preferences = PdfSavePreferences.NONE

Saving the document

Save the changes to a new file and close the editor:

editor.save_as("output.pdf")
editor.close()
except NutrientException as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()

Conclusion

The redaction workflow involves these core steps:

  1. Initialize — Open the PDF with a context manager and create an editor instance using PdfEditor.edit().
  2. Access pages — Retrieve the page collection. If the document is empty, add a page using standard dimensions (612 × 792 points).
  3. Target the area — Get the annotation collection for the specific page. Add a redaction marker by specifying the coordinates and dimensions in points.
  4. Style — Set the interior_color using ARGB values to define the fill color used after the content is removed.
  5. Configure save behavior — Use save_preferences to choose between automatic application or preserving markers for review.
  6. Finalize — Save the document and close the editor. Handle any NutrientException to manage processing errors.

Nutrient SDK automates PDF structures, coordinate transformations, and permanent data deletion. This ensures your application remains compliant with regulations such as GDPR or HIPAA without requiring manual implementation of complex redaction algorithms.