Redaction
Permanently remove text, images and annotations from PDFs by area, by text, by regular expression or by pattern with NexPDF for Flutter.
License module
Redaction needs the redaction module (Business tier and above).
Redaction in NexPDF is destructive: the text, images and annotations under the area are removed
from the file, not just covered, and an opaque box is painted over it: black, or white with
fill_white 1. Save the document afterwards.
In the reader
The native reader has a redaction mode where the user marks areas and
applies them: 'modeConfig': {'availableModes': ['viewer', 'redaction']}.
From code
The redaction functions have no Dart method. Call them
through dart:ffi on doc.handle:
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'nexpdf_ffi.dart';
// int32_t nexpdf_apply_redaction(NexPdfDocument *doc, size_t page_index,
// double llx, double lly, double urx, double ury, int32_t fill_white);
final applyRedaction = nexpdfLib.lookupFunction<
Int32 Function(Pointer<Void>, Size, Double, Double, Double, Double, Int32),
int Function(Pointer<Void>, int, double, double, double, double, int)>('nexpdf_apply_redaction');
// int32_t nexpdf_redact_matches(NexPdfDocument *doc, const char *query, int32_t mode, int32_t fill_white);
final redactMatches = nexpdfLib.lookupFunction<
Int32 Function(Pointer<Void>, Pointer<Utf8>, Int32, Int32),
int Function(Pointer<Void>, Pointer<Utf8>, int, int)>('nexpdf_redact_matches');
nexpdfCall(() => applyRedaction(doc.handle, 0, 72, 600, 300, 620, 0));
int redact(String query, int mode) =>
using((a) => nexpdfCall(() => redactMatches(doc.handle, query.toNativeUtf8(allocator: a), mode, 0)));
var n = redact('CONFIDENTIAL', 0);
n += redact(r'\b\d{3}-\d{2}-\d{4}\b', 1);
n += redact('email', 2);
print('$n areas redacted');
final redacted = doc.save();nexpdf_redact_matches finds and redacts every match in the document and returns the number of
areas redacted.
mode | query is |
|---|---|
0 | Plain text |
1 | A regular expression |
2 | A pattern id: email, phone, credit-card, iban, pt-nif, us-ssn, ipv4, url, date |
Review before redacting
Use search to show the matches to a reviewer first, and apply the
redaction once they are approved.
Redaction cannot be undone in the saved file. Keep the original if you may need it.