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

# PDFRedact

Sample 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 con

Sample 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 [UWP SDK](/core/get-started/frameworks/dotnet.md).

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

```csharp
//
// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
//

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Windows.Foundation;

using pdftron.PDF;
using pdftron.SDF;

using PDFNetUniversalSamples.ViewModels;

namespace PDFNetSamples
{
    public sealed class PDFRedactTest : Sample
    {
        public PDFRedactTest() :
            base("PDFRedact", "PDF Redactor is a separately licensable Add-on that offers options to remove (not just covering or obscuring) content within a region of PDF. ")
        {
        }

        public override IAsyncAction RunAsync()
        {
            return Task.Run(new System.Action(async () => {
                WriteLine("--------------------------------");
                WriteLine("Starting PDFRedact Test...");
                WriteLine("--------------------------------\n");

                try
                {
                    IList<RedactorRedaction> rarr = new List<RedactorRedaction>();
                    rarr.Add(new RedactorRedaction(1, new pdftron.PDF.Rect(0, 0, 600, 600), true, "Top Secret"));
                    rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(30, 30, 550, 550), true, "Top Secret"));
                    rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(100, 100, 200, 200), false, "bar"));
                    rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(300, 300, 400, 400), false, ""));
                    rarr.Add(new RedactorRedaction(2, new pdftron.PDF.Rect(500, 500, 600, 600), false, ""));
                    rarr.Add(new RedactorRedaction(3, new pdftron.PDF.Rect(0, 0, 700, 20), false, ""));
                    string output_file_path = Path.Combine(OutputPath, "redacted.pdf");
                    await RedactAsync(Path.Combine(InputPath, "newsletter.pdf"), output_file_path, rarr);
                }
                catch (Exception e)
                {
                    WriteLine(e.Message);
                }

                WriteLine("\n--------------------------------");
                WriteLine("Done PDFRedact Test.");
                WriteLine("--------------------------------\n");
            })).AsAsyncAction();
        }

        async Task RedactAsync(string input, string output, IList<RedactorRedaction> rarr)
        {
            using (PDFDoc doc = new PDFDoc(input))
            {
                doc.InitSecurityHandler();

                RedactorAppearance app = new RedactorAppearance();
                //app.Font = new System.Drawing.Font("Arial", 12);
                app.PositiveOverlayColor = Windows.UI.Colors.Red;
                app.NegativeOverlayColor = Windows.UI.Colors.WhiteSmoke;

                string output_file_path = Path.Combine(OutputPath, "redacted.pdf");
                Redactor.Redact(doc, rarr, app);
                await doc.SaveAsync(output_file_path, SDFDocSaveOptions.e_linearized);
                WriteLine("Result of redaction saved in " + output_file_path);
                await AddFileToOutputList(output_file_path).ConfigureAwait(false);
            }
        }
	}
}
```

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