Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Flutter Guides Redact pdfs

Create and Apply Redactions ​

Starting with 3.2.0, ComPDF Flutter SDK provides CPDFRedactAnnotation to mark content for removal. Creating a mark only adds an annotation. Content in the covered area is permanently removed when the redaction is applied.

In these examples, document is an opened CPDFDocument. The redaction application examples on this page apply to Android.

dart
import 'package:compdfkit_flutter/annotation/cpdf_redact_annotation.dart';
import 'package:compdfkit_flutter/util/cpdf_rectf.dart';
import 'package:flutter/material.dart';

Create Redaction Marks ​

dart
await document.addAnnotations([
  CPDFRedactAnnotation(
    page: 0,
    rect: const CPDFRectF(left: 72, top: 220, right: 300, bottom: 180),
    overlayText: 'Redacted',
    fillColor: Colors.black,
    outlineColor: Colors.red,
  ),
]);

page is zero-based. rect uses PDF page coordinates with the origin at the bottom-left corner. Configure the appearance with overlayText, fillColor, outlineColor, textAttribute, and alignment.

Read, Update, and Delete ​

After creating marks, read the annotations again to obtain objects with native uuid values. Use these objects for subsequent operations.

dart
final annotations = await document.pageAtIndex(0).getAnnotations();
final redactions = annotations.whereType<CPDFRedactAnnotation>().toList();
if (redactions.isNotEmpty) {
  final redaction = redactions.first;
  redaction.overlayText = 'Confidential';
  await document.updateAnnotation(redaction);
}

Before applying a redaction, you can delete its mark with document.removeAnnotation(redaction). Deleting the mark does not remove the original content.

Apply One Redaction ​

dart
if (redactions.isNotEmpty) {
  await document.applyRedaction(redactions.first);
  await document.save();
}

After successful application, the redaction annotation is removed. Do not reuse the original object for updates or application; read the page annotations again.

Apply All Redactions ​

dart
await document.applyRedactions();
await document.save();

Applying redactions permanently removes content in the covered areas. Deleting an annotation cannot restore that content. Retain a copy of the original file before processing. Saving unapplied marks alone does not remove sensitive content.