How to Redact Text and Regions

Curtis Chau
Curtis Chau
February 27, 2024
Updated December 10, 2024
Share:

Redact text involves the process of permanently removing or obscuring sensitive or confidential information from a document. This is typically done by covering the text with a black box or using a tool to delete the text entirely. Redaction ensures that the information cannot be accessed or viewed, providing privacy and security for sensitive content.

Similarly, redacting a region obscures the specified areas on the document. This process requires a bit more work since the coordinates, width, and height of the region must be provided.

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

-----s


Redact Text Example

Text redaction can be easily accomplished with the help of IronPdf. Use the RedactTextOnAllPages method to remove the specified phrase from the entire document. Let's use a PDF example document.

:path=/static-assets/pdf/content-code-examples/how-to/redact-text-redact-text.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric");

pdf.SaveAs("redacted.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")

' Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric")

pdf.SaveAs("redacted.pdf")
$vbLabelText   $csharpLabel

Output PDF

Result PDF from redacting the 'Alaric' phrase from all pages.

Use RedactTextOnPage and RedactTextOnPages methods to redact text from a single or multiple pages, respectively.

Here are the parameters of the redact text methods and their purposes:

  • ReplaceText: This is the text string that you want to redact.
  • CaseSensitive: A boolean value indicating whether the search should be case-sensitive. If true, it will match capital and lower-case letters exactly. The default is false.
  • OnlyMatchWholeWords: A boolean value specifying whether to match only whole words. The default is true.
  • DrawRectangles: A boolean value determining whether to draw black rectangles around the redacted areas. The default is true.
  • ReplacementText: This is the text that will be written in place of the redacted items. The default replacement text is "*".

Redact Regions Example

Redacting specific regions on the document works really well. Invoke the RedactRegionsOnAllPages method with the RectangleF object to redact the region of the targeted document. Let's use the same PDF example document from the example above.

:path=/static-assets/pdf/content-code-examples/how-to/redact-text-redact-region.cs
using IronPdf;
using IronSoftware.Drawing;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

RectangleF rectangle = new RectangleF(5, 700, 50, 50);

// Redact region on coordinates(5,700) with width and height 50 pixels
pdf.RedactRegionsOnAllPages(rectangle);

pdf.SaveAs("redactedRegion.pdf");
Imports IronPdf
Imports IronSoftware.Drawing

Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")

Private rectangle As New RectangleF(5, 700, 50, 50)

' Redact region on coordinates(5,700) with width and height 50 pixels
pdf.RedactRegionsOnAllPages(rectangle)

pdf.SaveAs("redactedRegion.pdf")
$vbLabelText   $csharpLabel

Output PDF

The result PDF is from redacting a region on the coordinates (5,700) with a width and height of 50 pixels.

Use RedactRegionOnPage and RedactRegionOnPages methods to redact regions from a single or multiple pages, respectively.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

Beyond development, Curtis has a strong interest in the Internet of Things (IoT), exploring innovative ways to integrate hardware and software. In his free time, he enjoys gaming and building Discord bots, combining his love for technology with creativity.