How to Redact Text and Regions
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.
How to Redact Text and Regions
- Download the C# library to redact text and regions
- Prepare the PDF document for redaction
- Use the
RedactTextOnAllPages
method to redact text on the entire document - Use the
RedactRegionsOnAllPages
method to redact regions on every pages of the document - Save or export PDF document as a new document
Install with NuGet
Install-Package IronPdf
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronPdf
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.
Install-Package IronPdf
Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip
Manually install into your project
Download DLLRedact 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 sample PDF.
: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")
Output PDF
Result PDF from redacting '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 region of the targeted document. Let's use the same PDF sample 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")
Output PDF
The result PDF is from redacting region on the coordinates(5,700) with width and height of 50 pixels.
Use RedactRegionOnPage
and RedactRegionOnPages
methods to redact regions from a single or multiple pages, respectively.