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

# PDFRedact

Sample Java 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 c

Sample Java 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 [Android SDK](/core/get-started/languages/java.md).

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

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

package com.pdftron.android.pdfnetsdksamples.samples;

import com.pdftron.android.pdfnetsdksamples.OutputListener;
import com.pdftron.android.pdfnetsdksamples.PDFNetSample;
import com.pdftron.android.pdfnetsdksamples.R;
import com.pdftron.android.pdfnetsdksamples.util.Utils;
import com.pdftron.pdf.PDFDoc;
import com.pdftron.pdf.Rect;
import com.pdftron.pdf.Redactor;
import com.pdftron.sdf.SDFDoc;

import java.util.ArrayList;

/**
 * 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.
 * <p>
 * The redaction process in PDFNet consists of two steps:
 * <p>
 * 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 'com.pdftron.pdf.PDFViewCtrl'
 * as shown in PDFView sample) or programmatically (e.g. using 'com.pdftron.pdf.TextSearch'
 * or 'com.pdftron.pdf.TextExtractor'). Up until the next step is performed, the user
 * can see, move and redefine these annotations.
 * b) Content removal: Using 'com.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.).
 * <p>
 * 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 extends PDFNetSample {

	private static OutputListener mOutputListener;

	private static ArrayList<String> mFileList = new ArrayList<>();

    public PDFRedactTest() {
        setTitle(R.string.sample_pdfredact_title);
        setDescription(R.string.sample_pdfredact_description);

        // The standard library does not include the Redaction feature.
        // If using the full library, please comment out the following
        // call.
        // DisableRun();
    }

	@Override
	public void run(OutputListener outputListener) {
		super.run(outputListener);
		mOutputListener = outputListener;
		mFileList.clear();
		printHeader(outputListener);
        // Relative paths to folders containing test files.

        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(Utils.getAssetTempFile(INPUT_PATH + "newsletter.pdf").getAbsolutePath(), Utils.createExternalFile("redacted.pdf", mFileList).getAbsolutePath(), vec, app);

            mOutputListener.println("Done...");
        } catch (Exception e) {
            mOutputListener.printError(e.getStackTrace());
        }

		for (String file : mFileList) {
			addToFileList(file);
		}
		printFooter(outputListener);
	}

    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) {
            mOutputListener.printError(e.getStackTrace());
        }
    }

}
```

{% endcode %}
{% endtab %}

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

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

package com.pdftron.android.pdfnetsdksamples.samples

import com.pdftron.android.pdfnetsdksamples.OutputListener
import com.pdftron.android.pdfnetsdksamples.PDFNetSample
import com.pdftron.android.pdfnetsdksamples.R
import com.pdftron.android.pdfnetsdksamples.util.Utils
import com.pdftron.pdf.PDFDoc
import com.pdftron.pdf.Rect
import com.pdftron.pdf.Redactor
import com.pdftron.sdf.SDFDoc
import java.util.*

/**
 * 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 'com.pdftron.pdf.PDFViewCtrl'
 * as shown in PDFView sample) or programmatically (e.g. using 'com.pdftron.pdf.TextSearch'
 * or 'com.pdftron.pdf.TextExtractor'). Up until the next step is performed, the user
 * can see, move and redefine these annotations.
 * b) Content removal: Using 'com.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 PDFRedactTest : PDFNetSample() {
    init {
        setTitle(R.string.sample_pdfredact_title)
        setDescription(R.string.sample_pdfredact_description)

        // The standard library does not include the Redaction feature.
        // If using the full library, please comment out the following
        // call.
        // DisableRun();
    }

    override fun run(outputListener: OutputListener?) {
        super.run(outputListener)
        mOutputListener = outputListener
        mFileList.clear()
        printHeader(outputListener!!)
        // Relative paths to folders containing test files.

        try {
            val vec = arrayOfNulls<Redactor.Redaction>(7)
            vec[0] = Redactor.Redaction(1, Rect(100.0, 100.0, 550.0, 600.0), false, "Top Secret")
            vec[1] = Redactor.Redaction(2, Rect(30.0, 30.0, 450.0, 450.0), true, "Negative Redaction")
            vec[2] = Redactor.Redaction(2, Rect(0.0, 0.0, 100.0, 100.0), false, "Positive")
            vec[3] = Redactor.Redaction(2, Rect(100.0, 100.0, 200.0, 200.0), false, "Positive")
            vec[4] = Redactor.Redaction(2, Rect(300.0, 300.0, 400.0, 400.0), false, "")
            vec[5] = Redactor.Redaction(2, Rect(500.0, 500.0, 600.0, 600.0), false, "")
            vec[6] = Redactor.Redaction(3, Rect(0.0, 0.0, 700.0, 20.0), false, "")

            val app = Redactor.Appearance()
            app.redactionOverlay = true
            app.border = false
            app.showRedactedContentRegions = true

            redact(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "newsletter.pdf")!!.absolutePath, Utils.createExternalFile("redacted.pdf", mFileList).absolutePath, vec, app)

            mOutputListener!!.println("Done...")
        } catch (e: Exception) {
            mOutputListener!!.printError(e.stackTrace)
        }

        for (file in mFileList) {
            addToFileList(file)
        }
        printFooter(outputListener)
    }

    companion object {

        private var mOutputListener: OutputListener? = null

        private val mFileList = ArrayList<String>()

        fun redact(input: String, output: String, vec: Array<Redactor.Redaction?>, app: Redactor.Appearance) {
            try {
                PDFDoc(input).use { doc ->
                    if (doc.initSecurityHandler()) {
                        Redactor.redact(doc, vec, app, false, true)
                        doc.save(output, SDFDoc.SaveMode.REMOVE_UNUSED, null)
                    }
                }
            } catch (e: Exception) {
                mOutputListener!!.printError(e.stackTrace)
            }

        }
    }

}
```

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