> 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/core/get-started/samples/pdfredacttest.md).

# Redact PDFs - PDFRedact

Sample code for using Apryse SDK to remove potentially sensitive content within PDF documents.  Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby and VB.

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/core/get-started/get-started.md" class="button primary">Server SDK</a><a href="https://apryse.com/capabilities#Redaction" class="button primary">Package: Redaction</a><a href="https://showcase.apryse.com/redaction" class="button primary">Live demo</a>
{% endhint %}

Sample 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. Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby and VB.

### **Implementation steps**

To redact files with Apryse Server SDK:

Step 1: Follow [get started with Server SDK in your preferred language or framework](/core/get-started/get-started.md) Step 2: Add the sample code provided in this guide

To use this feature in production, your license key will need the [Redaction Package](https://apryse.com/capabilities#Redaction). Trial keys already include all packages.

Learn more about our [Server SDK](/core/get-started/get-started.md).

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

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

using System;
using System.IO;
using System.Collections;

using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace PDFNetSamples
{
	// 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.
	class Class1
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
		static Class1() {}
		
		static void Redact(string input, string output, ArrayList rarr, Redactor.Appearance app)
		{
			using (PDFDoc doc = new PDFDoc(input))
			{
				doc.InitSecurityHandler();
				Redactor.Redact(doc, rarr, app, false, true);
				doc.Save(output, SDFDoc.SaveOptions.e_linearized);
			}
		}

		/// <summary>
		/// The following sample illustrates how to redact a PDF document using 'pdftron.PDF.Redactor'.
		/// </summary>
		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);

			string input_path = "../../../../TestFiles/";
			string output_path = "../../../../TestFiles/Output/";
			try
			{
				ArrayList rarr = new ArrayList();
				rarr.Add(new Redactor.Redaction(1, new Rect(100, 100, 550, 600), false, "Top Secret"));
				rarr.Add(new Redactor.Redaction(2, new Rect(30, 30, 450, 450), true, "Negative Redaction"));
				rarr.Add(new Redactor.Redaction(2, new Rect(0, 0, 100, 100), false, "Positive"));
				rarr.Add(new Redactor.Redaction(2, new Rect(100, 100, 200, 200), false, "Positive"));
				rarr.Add(new Redactor.Redaction(2, new Rect(300, 300, 400, 400), false, ""));
				rarr.Add(new Redactor.Redaction(2, new Rect(500, 500, 600, 600), false, ""));
				rarr.Add(new Redactor.Redaction(3, new Rect(0, 0, 700, 20), false, ""));

				Redactor.Appearance app = new Redactor.Appearance();
				app.RedactionOverlay = true;
				app.Border = false;
				app.ShowRedactedContentRegions = true;

				Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", rarr, app);

				Console.WriteLine("Done...");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}
			PDFNet.Terminate();
		}
	}
}
```

{% endcode %}
{% endtab %}

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

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

// 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 VectorRedaction, app Appearance){
    doc := NewPDFDoc(input)
    if doc.InitSecurityHandler(){
        RedactorRedact(doc, vec, app, false, true)
        doc.Save(output, uint(SDFDocE_linearized))
	}
}                                  

func main(){

    // Relative path to the folder containing the test files.
    inputPath := "../../TestFiles/"
    outputPath := "../../TestFiles/Output/"
    
    PDFNetInitialize(PDFTronLicense.Key)
    
    vec := NewVectorRedaction()
    vec.Add(NewRedaction(1, NewRect(100.0, 100.0, 550.0, 600.0), false, "Top Secret"))
    vec.Add(NewRedaction(2, NewRect(30.0, 30.0, 450.0, 450.0), true, "Negative Redaction"))
    vec.Add(NewRedaction(2, NewRect(0.0, 0.0, 100.0, 100.0), false, "Positive"))
    vec.Add(NewRedaction(2, NewRect(100.0, 100.0, 200.0, 200.0), false, "Positive"))
    vec.Add(NewRedaction(2, NewRect(300.0, 300.0, 400.0, 400.0), false, ""))
    vec.Add(NewRedaction(2, NewRect(500.0, 500.0, 600.0, 600.0), false, ""))
    vec.Add(NewRedaction(3, NewRect(0.0, 0.0, 700.0, 20.0), false, ""))
	
    app := NewAppearance() 
    app.SetRedactionOverlay(true)
    app.SetBorder(false)
    app.SetShowRedactedContentRegions(true)
    Redact(inputPath + "newsletter.pdf", outputPath + "redacted.pdf", vec, app)
    
    PDFNetTerminate()
    fmt.Println("Done...")
}
```

{% endcode %}
{% endtab %}

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

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

import java.lang.*;
import java.awt.*;

import com.pdftron.pdf.*;
import com.pdftron.sdf.SDFDoc;


// 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.
public class PDFRedactTest {

    public static void redact(String input, String output, Redactor.Redaction[] vec, Redactor.Appearance app) {
        try (PDFDoc doc = new PDFDoc(input)) {
            if (doc.initSecurityHandler()) {
                Redactor.redact(doc, vec, app, false, true);
                doc.save(output, SDFDoc.SaveMode.REMOVE_UNUSED, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        // Relative paths to folders containing test files.
        String input_path = "../../TestFiles/";
        String output_path = "../../TestFiles/Output/";

        PDFNet.initialize(PDFTronLicense.Key());

        try {
            Redactor.Redaction[] vec = new Redactor.Redaction[7];
            vec[0] = new Redactor.Redaction(1, new Rect(100, 100, 550, 600), false, "Top Secret");
            vec[1] = new Redactor.Redaction(2, new Rect(30, 30, 450, 450), true, "Negative Redaction");
            vec[2] = new Redactor.Redaction(2, new Rect(0, 0, 100, 100), false, "Positive");
            vec[3] = new Redactor.Redaction(2, new Rect(100, 100, 200, 200), false, "Positive");
            vec[4] = new Redactor.Redaction(2, new Rect(300, 300, 400, 400), false, "");
            vec[5] = new Redactor.Redaction(2, new Rect(500, 500, 600, 600), false, "");
            vec[6] = new Redactor.Redaction(3, new Rect(0, 0, 700, 20), false, "");
            
            Redactor.Appearance app = new Redactor.Appearance();
            app.redactionOverlay = true;
            app.border = false;
            app.showRedactedContentRegions = true;

            redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app);

            System.out.println("Done...");
        } catch (Exception e) {
            e.printStackTrace();
        }
        PDFNet.terminate();
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

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

#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/Redactor.h>

#include <iostream>
#include <vector>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace std;

using namespace pdftron;
using namespace Common;
using namespace SDF;
using namespace PDF;

// 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.

static void Redact(const string& input, const string& output, const vector<Redactor::Redaction>& vec, Redactor::Appearance app) 
{
	PDFDoc doc(input);
	if (doc.InitSecurityHandler()) {
		Redactor::Redact(doc, vec, app, false, true);
		doc.Save(output, SDFDoc::e_linearized, 0);
	}
}

int main(int argc, char *argv[])
{
	int ret = 0;

	// Relative paths to folders containing test files.
	string input_path =  "../../TestFiles/";
	string output_path = "../../TestFiles/Output/";

	PDFNet::Initialize(LicenseKey);

	try  
	{	 
		vector<Redactor::Redaction> vec;
		vec.push_back(Redactor::Redaction(1, Rect(100, 100, 550, 600), false, "Top Secret"));
		vec.push_back(Redactor::Redaction(2, Rect(30, 30, 450, 450), true, "Negative Redaction"));
		vec.push_back(Redactor::Redaction(2, Rect(0, 0, 100, 100), false, "Positive"));
		vec.push_back(Redactor::Redaction(2, Rect(100, 100, 200, 200), false, "Positive"));
		vec.push_back(Redactor::Redaction(2, Rect(300, 300, 400, 400), false, ""));
		vec.push_back(Redactor::Redaction(2, Rect(500, 500, 600, 600), false, ""));
		vec.push_back(Redactor::Redaction(3, Rect(0, 0, 700, 20), false, ""));

		Redactor::Appearance app;
		app.RedactionOverlay = true;
		app.Border = false;
		app.ShowRedactedContentRegions = true;

		Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app);

		cout << "Done..." << endl;
	}
	catch(Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch(...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	PDFNet::Terminate();
	return ret;
}
```

{% endcode %}
{% endtab %}

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

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

// 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.

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {

  exports.runPDFRedactTest = () => {
    const redact = async(input, output, vec, app) => {
      const doc = await PDFNet.PDFDoc.createFromFilePath(input);
      if (await doc.initSecurityHandler()) {
        PDFNet.Redactor.redact(doc, vec, app, false, true);
        await doc.save(output, PDFNet.SDFDoc.SaveOptions.e_linearized);
      }
    };

    const main = async() => {
      // Relative path to the folder containing test files.
      const inputPath = '../TestFiles/';
      try {
        const redactionArray = []; // we will contain a list of redaction objects in this array
        redactionArray.push(await PDFNet.Redactor.redactionCreate(1, (await PDFNet.Rect.init(100, 100, 550, 600)), false, 'Top Secret'));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(30, 30, 450, 450)), true, 'Negative Redaction'));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(0, 0, 100, 100)), false, 'Positive'));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(100, 100, 200, 200)), false, 'Positive'));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(300, 300, 400, 400)), false, ''));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(500, 500, 600, 600)), false, ''));
        redactionArray.push(await PDFNet.Redactor.redactionCreate(3, (await PDFNet.Rect.init(0, 0, 700, 20)), false, ''));

        const appear = { redaction_overlay: true, border: false, show_redacted_content_regions: true };
        await redact(inputPath + 'newsletter.pdf', inputPath + 'Output/redacted.pdf', redactionArray, appear);

        console.log('Done...');
      } catch (err) {
        console.log(err.stack);
      }
    };
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
  };
  exports.runPDFRedactTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=PDFRedactTest.js
```

{% endcode %}
{% endtab %}

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

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *


# 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.

def Redact(input, output, vec, app):
    doc = PDFDoc(input)
    if doc.InitSecurityHandler():
        Redactor.Redact(doc, vec, app, False, True)
        doc.Save(output, SDFDoc.e_linearized)
                                  

def main():
    # Relative path to the folder containing the test files.
    input_path = "../../TestFiles/"
    output_path = "../../TestFiles/Output/"
    
    PDFNet.Initialize(LicenseKey)
    
    vec = VectorRedaction()
    vec.append(Redaction(1, Rect(100, 100, 550, 600), False, "Top Secret"))
    vec.append(Redaction(2, Rect(30, 30, 450, 450), True, "Negative Redaction"))
    vec.append(Redaction(2, Rect(0, 0, 100, 100), False, "Positive"))
    vec.append(Redaction(2, Rect(100, 100, 200, 200), False, "Positive"))
    vec.append(Redaction(2, Rect(300, 300, 400, 400), False, ""))
    vec.append(Redaction(2, Rect(500, 500, 600, 600), False, ""))
    vec.append(Redaction(3, Rect(0, 0, 700, 20), False, ""))
	
    app = Appearance() 
    app.RedactionOverlay = True
    app.Border = False
    app.ShowRedactedContentRegions = True
    Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app)
    
    PDFNet.Terminate()
    print("Done...")

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

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

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// 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.
	
function Redact($input, $output, $vec, $app) {
	$doc = new PDFDoc($input);
	if ($doc->InitSecurityHandler()) {
		Redactor::Redact($doc, $vec, $app, false, true);
		$doc->Save($output, SDFDoc::e_linearized);
	}

}

	# Relative path to the folder containing the test files.
	$input_path = getcwd()."/../../TestFiles/";
	$output_path = $input_path."Output/";

	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.

	$vec = new VectorRedaction();
	$vec->push(new Redaction(1, new Rect(100.0, 100.0, 550.0, 600.0), false, "Top Secret"));
	$vec->push(new Redaction(2, new Rect(30.0, 30.0, 450.0, 450.0), true, "Negative Redaction"));
	$vec->push(new Redaction(2, new Rect(0.0, 0.0, 100.0, 100.0), false, "Positive"));
	$vec->push(new Redaction(2, new Rect(100.0, 100.0, 200.0, 200.0), false, "Positive"));
   	$vec->push(new Redaction(2, new Rect(300.0, 300.0, 400.0, 400.0), false, ""));
	$vec->push(new Redaction(2, new Rect(500.0, 500.0, 600.0, 600.0), false, ""));
	$vec->push(new Redaction(3, new Rect(0.0, 0.0, 700.0, 20.0), false, ""));
	
	$app = new Appearance(); 
	$app->RedactionOverlay = true;
	$app->Border = false;
	$app->ShowRedactedContentRegions = true;
	Redact($input_path."newsletter.pdf", $output_path."redacted.pdf", $vec, $app);
    PDFNet::Terminate();
	echo "Done...\n";	
?>
```

{% endcode %}
{% endtab %}

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

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true


# 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.

def Redact(input, output, vec, app)
	doc = PDFDoc.new(input)
	if doc.InitSecurityHandler
		Redactor.Redact(doc, vec, app, false, true)
		doc.Save(output, SDFDoc::E_linearized)
	end
end

	# Relative path to the folder containing the test files.
	input_path = "../../TestFiles/"
	output_path = "../../TestFiles/Output/"
	
	PDFNet.Initialize(PDFTronLicense.Key)
	
	vec = [Redaction.new(1, Rect.new(100, 100, 550, 600), false, "Top Secret"),
		Redaction.new(2, Rect.new(30, 30, 450, 450), true, "Negative Redaction"),
		Redaction.new(2, Rect.new(0, 0, 100, 100), false, "Positive"),
		Redaction.new(2, Rect.new(100, 100, 200, 200), false, "Positive"),
		Redaction.new(2, Rect.new(300, 300, 400, 400), false, ""),
		Redaction.new(2, Rect.new(500, 500, 600, 600), false, ""),
        Redaction.new(3, Rect.new(0, 0, 700, 20), false, "")]

    app = Appearance.new
    app.RedactionOverlay = true
    app.Border = false
    app.ShowRedactedContentRegions = true
	
    Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app)
	PDFNet.Terminate
	puts "Done..."
```

{% endcode %}
{% endtab %}

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

```vb
'
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
'

Imports System
Imports System.Collections

Imports pdftron
Imports pdftron.Common
Imports pdftron.Filters
Imports pdftron.SDF
Imports pdftron.PDF

Module PDFRedactTestVB
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' 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.
    '
    ' The following sample illustrates how to redact a PDF document using 'pdftron.PDF.Redactor'.
    Sub Main()
        PDFNet.Initialize(PDFTronLicense.Key)

        Dim input_path As String = "../../../../TestFiles/"
        Dim output_path As String = "../../../../TestFiles/Output/"
        Dim input_filename As String = "newsletter.pdf"

        Try
            Dim rarr As ArrayList = New ArrayList
            rarr.Add(New Redactor.Redaction(1, New Rect(100, 100, 550, 600), False, "Top Secret"))
            rarr.Add(New Redactor.Redaction(2, New Rect(30, 30, 450, 450), True, "Negative Redaction"))
            rarr.Add(New Redactor.Redaction(2, New Rect(0, 0, 100, 100), False, "Positive"))
            rarr.Add(New Redactor.Redaction(2, New Rect(100, 100, 200, 200), False, "Positive"))
            rarr.Add(New Redactor.Redaction(2, New Rect(300, 300, 400, 400), False, ""))
            rarr.Add(New Redactor.Redaction(2, New Rect(500, 500, 600, 600), False, ""))
            rarr.Add(New Redactor.Redaction(3, New Rect(0, 0, 700, 20), False, ""))


            Dim app As Redactor.Appearance = New Redactor.Appearance()
            app.RedactionOverlay = True
            app.Border = False
            app.ShowRedactedContentRegions = True

            Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", rarr, app)

            Console.WriteLine("Done...")
        Catch ex As PDFNetException
            Console.WriteLine(ex.Message)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        PDFNet.Terminate()
    End Sub

    Sub Redact(ByVal input As String, ByVal output As String, ByVal rarr As ArrayList, ByVal app As Redactor.Appearance)
        Try
            Using doc As PDFDoc = New PDFDoc(input)
                doc.InitSecurityHandler()

                Redactor.Redact(doc, rarr, app, False, True)
                doc.Save(output, SDFDoc.SaveOptions.e_linearized)
            End Using
        Catch ex As PDFNetException
            Console.WriteLine(ex.Message)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Module
```

{% 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/core/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.
