PDFRedact

Sample Obj-C code for using Apryse SDK to remove potentially sensitive content within PDF documents. Using 'pdftron.PDF.Redactor' makes sure that if a portion of an image, text, or vector graphics is contained in a redaction region, that portion is destroyed and is not simply hidden with clipping or image masks. Learn more about our iOS SDK.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9// PDF Redactor is a separately licensable Add-on that offers options to remove
10// (not just covering or obscuring) content within a region of PDF.
11// With printed pages, redaction involves blacking-out or cutting-out areas of
12// the printed page. With electronic documents that use formats such as PDF,
13// redaction typically involves removing sensitive content within documents for
14// safe distribution to courts, patent and government institutions, the media,
15// customers, vendors or any other audience with restricted access to the content.
16//
17// The redaction process in PDFNet consists of two steps:
18//
19// a) Content identification: A user applies redact annotations that specify the
20// pieces or regions of content that should be removed. The content for redaction
21// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl'
22// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
23// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user
24// can see, move and redefine these annotations.
25// b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs
26// PDFNet to apply the redact regions, after which the content in the area specified
27// by the redact annotations is removed. The redaction function includes number of
28// options to control the style of the redaction overlay (including color, text,
29// font, border, transparency, etc.).
30//
31// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics
32// is contained in a redaction region, that portion of the image or path data is
33// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also
34// be used to review and remove metadata and other content that can exist in a PDF
35// document, including XML Forms Architecture (XFA) content and Extensible Metadata
36// Platform (XMP) content.
37
38void Redact(NSString* input, NSString* output, PTVectorRedaction *vec, PTAppearance *app) {
39 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: input];
40 if ([doc InitSecurityHandler]) {
41 [PTRedactor Redact: doc red_arr: vec app: app ext_neg_mode: NO page_coord_sys: YES];
42 [doc SaveToFile: output flags: e_ptlinearized ];
43 }
44}
45
46int main(int argc, char *argv[])
47{
48 @autoreleasepool {
49
50 int ret = 0;
51
52 [PTPDFNet Initialize: 0];
53
54 PTPDFRect * rect1 = [[PTPDFRect alloc] init];
55 [rect1 Set: 100 y1: 100 x2: 550 y2: 600];
56
57 PTPDFRect * rect2 = [[PTPDFRect alloc] init];
58 [rect2 Set: 30 y1: 30 x2: 450 y2: 450];
59
60 PTPDFRect * rect3 = [[PTPDFRect alloc] init];
61 [rect3 Set: 0 y1: 0 x2: 100 y2: 100];
62
63 PTPDFRect * rect4 = [[PTPDFRect alloc] init];
64 [rect4 Set: 100 y1: 100 x2: 200 y2: 200];
65
66 PTPDFRect * rect5 = [[PTPDFRect alloc] init];
67 [rect5 Set: 300 y1: 300 x2: 400 y2: 400];
68
69 PTPDFRect * rect6 = [[PTPDFRect alloc] init];
70 [rect6 Set: 500 y1: 500 x2: 600 y2: 600];
71
72 PTPDFRect * rect7 = [[PTPDFRect alloc] init];
73 [rect7 Set: 0 y1: 0 x2: 700 y2: 20];
74
75 PTVectorRedaction *vec = [[PTVectorRedaction alloc] init];
76 [vec add: [[PTRedaction alloc] initWithPage_num: 1 bbox: rect1 negative: NO text: @"Top Secret"]];
77 [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect2 negative: YES text: @"Negative Redaction"]];
78 [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect3 negative: NO text: @"Positive"]];
79 [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect4 negative: NO text: @"Positive"]];
80 [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect5 negative: NO text: @""]];
81 [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect6 negative: NO text: @""]];
82 [vec add: [[PTRedaction alloc] initWithPage_num: 3 bbox: rect7 negative: NO text: @""]];
83
84 PTAppearance *app = [[PTAppearance alloc] init];
85 [app setRedactionOverlay: YES];
86 [app setBorder: NO];
87 [app setShowRedactedContentRegions: YES];
88
89 Redact(@"../../TestFiles/newsletter.pdf", @"../../TestFiles/Output/redacted.pdf", vec, app);
90
91 NSLog(@"Done...");
92 [PTPDFNet Terminate: 0];
93 return ret;
94 }
95}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales