> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/get-started/samples/pdfredacttest.md).

# 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

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](/ios/guides.md).

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#import <OBJC/PDFNetOBJC.h>
#import <Foundation/Foundation.h>

// PDF Redactor is a separately licensable Add-on that offers options to remove 
// (not just covering or obscuring) content within a region of PDF. 
// With printed pages, redaction involves blacking-out or cutting-out areas of 
// the printed page. With electronic documents that use formats such as PDF, 
// redaction typically involves removing sensitive content within documents for 
// safe distribution to courts, patent and government institutions, the media, 
// customers, vendors or any other audience with restricted access to the content. 
//
// The redaction process in PDFNet consists of two steps:
// 
//  a) Content identification: A user applies redact annotations that specify the 
// pieces or regions of content that should be removed. The content for redaction 
// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl' 
// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user 
// can see, move and redefine these annotations.
//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs 
// PDFNet to apply the redact regions, after which the content in the area specified 
// by the redact annotations is removed. The redaction function includes number of 
// options to control the style of the redaction overlay (including color, text, 
// font, border, transparency, etc.).
// 
// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics 
// is contained in a redaction region, that portion of the image or path data is 
// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also 
// be used to review and remove metadata and other content that can exist in a PDF 
// document, including XML Forms Architecture (XFA) content and Extensible Metadata 
// Platform (XMP) content.

void Redact(NSString* input, NSString* output, PTVectorRedaction *vec, PTAppearance *app) {
    PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: input];
    if ([doc InitSecurityHandler]) {
        [PTRedactor Redact: doc red_arr: vec app: app ext_neg_mode: NO page_coord_sys: YES];
        [doc SaveToFile: output flags: e_ptlinearized ];
    }   
}

int main(int argc, char *argv[])
{
    @autoreleasepool {

        int ret = 0;

        [PTPDFNet Initialize: 0];
        
        PTPDFRect * rect1 = [[PTPDFRect alloc] init];
        [rect1 Set: 100 y1: 100 x2: 550 y2: 600];
        
        PTPDFRect * rect2 = [[PTPDFRect alloc] init];
        [rect2 Set: 30 y1: 30 x2: 450 y2: 450];
        
        PTPDFRect * rect3 = [[PTPDFRect alloc] init];
        [rect3 Set: 0 y1: 0 x2: 100 y2: 100];
        
        PTPDFRect * rect4 = [[PTPDFRect alloc] init];
        [rect4 Set: 100 y1: 100 x2: 200 y2: 200];
        
        PTPDFRect * rect5 = [[PTPDFRect alloc] init];
        [rect5 Set: 300 y1: 300 x2: 400 y2: 400];
        
        PTPDFRect * rect6 = [[PTPDFRect alloc] init];
        [rect6 Set: 500 y1: 500 x2: 600 y2: 600];
        
        PTPDFRect * rect7 = [[PTPDFRect alloc] init];
        [rect7 Set: 0 y1: 0 x2: 700 y2: 20];

        PTVectorRedaction *vec = [[PTVectorRedaction alloc] init];
        [vec add: [[PTRedaction alloc] initWithPage_num: 1 bbox: rect1 negative: NO text: @"Top Secret"]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect2 negative: YES text: @"Negative Redaction"]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect3 negative: NO text: @"Positive"]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect4 negative: NO text: @"Positive"]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect5 negative: NO text: @""]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 2 bbox: rect6 negative: NO text: @""]];
        [vec add: [[PTRedaction alloc] initWithPage_num: 3 bbox: rect7 negative: NO text: @""]];
        
        PTAppearance *app = [[PTAppearance alloc] init];
        [app setRedactionOverlay: YES];
        [app setBorder: NO];
        [app setShowRedactedContentRegions: YES];

        Redact(@"../../TestFiles/newsletter.pdf", @"../../TestFiles/Output/redacted.pdf", vec, app);

        NSLog(@"Done...");
        [PTPDFNet Terminate: 0];            
        return ret;
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import PDFNet
import Foundation

// PDF Redactor is a separately licensable Add-on that offers options to remove
// (not just covering or obscuring) content within a region of PDF.
// With printed pages, redaction involves blacking-out or cutting-out areas of
// the printed page. With electronic documents that use formats such as PDF,
// redaction typically involves removing sensitive content within documents for
// safe distribution to courts, patent and government institutions, the media,
// customers, vendors or any other audience with restricted access to the content.
//
// The redaction process in PDFNet consists of two steps:
//
//  a) Content identification: A user applies redact annotations that specify the
// pieces or regions of content that should be removed. The content for redaction
// can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl'
// as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
// or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user
// can see, move and redefine these annotations.
//  b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs
// PDFNet to apply the redact regions, after which the content in the area specified
// by the redact annotations is removed. The redaction function includes number of
// options to control the style of the redaction overlay (including color, text,
// font, border, transparency, etc.).
//
// PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics
// is contained in a redaction region, that portion of the image or path data is
// destroyed and is not simply hidden with clipping or image masks. PDFNet API can also
// be used to review and remove metadata and other content that can exist in a PDF
// document, including XML Forms Architecture (XFA) content and Extensible Metadata
// Platform (XMP) content.

func Redact(input: String, output: String, vec: PTVectorRedaction, app: PTAppearance) {
    let doc: PTPDFDoc = PTPDFDoc(filepath: input)
    if doc.initSecurityHandler() {
        PTRedactor.redact(doc, red_arr: vec, app: app, ext_neg_mode: false, page_coord_sys: true)
        doc.save(toFile: output, flags: e_ptlinearized.rawValue)
    }
}

func runPDFRedactTest() -> Int {
    return autoreleasepool {
        var ret: Int = 0
        
        
        
        do {
            try PTPDFNet.catchException {
        
                let rect1: PTPDFRect = PTPDFRect(x1: 100, y1: 100, x2: 550, y2: 600)
                
                let rect2: PTPDFRect = PTPDFRect(x1: 30, y1: 30, x2: 450, y2: 450)
                
                let rect3: PTPDFRect = PTPDFRect(x1: 0, y1: 0, x2: 100, y2: 100)
                
                let rect4: PTPDFRect = PTPDFRect(x1: 100, y1: 100, x2: 200, y2: 200)
                
                let rect5: PTPDFRect = PTPDFRect(x1: 300, y1: 300, x2: 400, y2: 400)
                
                let rect6: PTPDFRect = PTPDFRect(x1: 500, y1: 500, x2: 600, y2: 600)
                
                let rect7: PTPDFRect = PTPDFRect(x1: 0, y1: 0, x2: 700, y2: 20)
                
                let vec: PTVectorRedaction = PTVectorRedaction()
                vec.add(PTRedaction(page_num: 1, bbox: rect1, negative: false, text: "Top Secret"))
                vec.add(PTRedaction(page_num: 2, bbox: rect2, negative: true, text: "Negative Redaction"))
                vec.add(PTRedaction(page_num: 2, bbox: rect3, negative: false, text: "Positive"))
                vec.add(PTRedaction(page_num: 2, bbox: rect4, negative: false, text: "Positive"))
                vec.add(PTRedaction(page_num: 2, bbox: rect5, negative: false, text: ""))
                vec.add(PTRedaction(page_num: 2, bbox: rect6, negative: false, text: ""))
                vec.add(PTRedaction(page_num: 3, bbox: rect7, negative: false, text: ""))
                
                let app: PTAppearance = PTAppearance()
                app.setRedactionOverlay(true)
                app.setBorder(false)
                
                Redact(input: Bundle.main.path(forResource: "newsletter", ofType: "pdf")!, output: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("redacted.pdf").path, vec: vec, app: app)
                
                print("Done...")
            }
        } catch let e as NSError {
            print("\(e)")
            ret = 1
        }
        
        return ret
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/get-started/samples/pdfredacttest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
