Redaction
Redaction annotations permanently remove or obscure sensitive PDF content. Unlike other annotations, redaction has mark and apply phases: marking previews the effect; apply permanently removes content under the marked areas.
Important
After apply, content under redacted areas is permanently removed and cannot be recovered. Back up the document before applying.
Workflow
- Create — Add Redact annotation over target area
- Configure — Overlay color, text, etc.
- Preview — Original content remains until apply
- Apply — Permanently remove content; annotations are removed
Core methods
| Method | Description |
|---|---|
getQuadPoints / setQuadPoints: | Redaction region (precise text areas) |
getFillColor / setFillColor: | Mark-phase fill (preview) |
getApplyFillColor / setApplyFillColor: | Fill after apply |
getOverlayText / setOverlayText: | Overlay text after apply |
isOverlayTextRepeated / enableRepeatOverlayText: | Repeat overlay text |
getOverlayTextAlignment / setOverlayTextAlignment: | Overlay alignment |
getDefaultAppearance / setDefaultAppearance: | Overlay font appearance |
enableAutoFontSize | Auto-fit overlay font size |
apply | Apply redaction — permanent removal |
Example: create and apply
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFDoc *doc = [[FSPDFDoc alloc] initWithPath:@"path/to/Sample.pdf"];
[doc load:nil];
FSPDFPage *page = [doc getPage:0];
FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:700 right1:350 top1:720];
FSAnnot *annot = [page addAnnot:FSAnnotRedact rect:rect];
FSRedact *redact = [[FSRedact alloc] initWithAnnot:annot];
[redact setFillColor:0xFFFF0000];
[redact setApplyFillColor:0xFF000000];
[redact setOverlayText:@"已脱敏"];
[redact setOverlayTextAlignment:1];
FSDefaultAppearance *da = [[FSDefaultAppearance alloc] init];
[da setText_size:12];
[da setText_color:0xFFFFFFFF];
[redact setDefaultAppearance:da];
[redact resetAppearanceStream];
[doc saveAs:@"path/to/preview.pdf" saveFlags:FSPDFDocSaveFlagNormal];
[redact apply];
[doc saveAs:@"path/to/redacted.pdf" saveFlags:FSPDFDocSaveFlagNormal];Example: precise text redaction
Combine text search with QuadPoints:
objc
#import <FoxitRDK/FSPDFObjC.h>
FSTextSearch *textSearch = [[FSTextSearch alloc] initWithDocument:doc cancel_callback:nil];
[textSearch setPattern:@"机密信息"];
if ([textSearch findNext]) {
FSRectFArray *rects = [textSearch getMatchRects];
FSQuadPointsArray *quadPointsArray = [[FSQuadPointsArray alloc] init];
for (int i = 0; i < [rects getSize]; i++) {
FSRectF *r = [rects getAt:i];
FSQuadPoints *qp = [[FSQuadPoints alloc] init];
FSPointF *first = [[FSPointF alloc] init];
[first set:[r getLeft] y:[r getTop]];
FSPointF *second = [[FSPointF alloc] init];
[second set:[r getRight] y:[r getTop]];
FSPointF *third = [[FSPointF alloc] init];
[third set:[r getLeft] y:[r getBottom]];
FSPointF *fourth = [[FSPointF alloc] init];
[fourth set:[r getRight] y:[r getBottom]];
[qp setFirst:first];
[qp setSecond:second];
[qp setThird:third];
[qp setFourth:fourth];
[quadPointsArray add:qp];
}
FSRectF *emptyRect = [[FSRectF alloc] initWithLeft1:0 bottom1:0 right1:0 top1:0];
FSAnnot *annot = [page addAnnot:FSAnnotRedact rect:emptyRect];
FSRedact *redact = [[FSRedact alloc] initWithAnnot:annot];
[redact setQuadPoints:quadPointsArray];
[redact setApplyFillColor:0xFF000000];
[redact resetAppearanceStream];
[redact apply];
}