How to Redact Text and Regions in PDFs Using IronPDF and C#

Curtis Chau
Curtis Chau
Updated: November 4, 2026

IronPDF enables C# developers to permanently remove sensitive text and regions from PDF documents through simple redaction methods, ensuring data privacy and compliance by covering content with black boxes or replacement text.

Redacting text involves permanently removing or obscuring sensitive information from a document. This is typically done by covering text with a black box or using a tool to delete it entirely. Redaction ensures that information cannot be accessed or viewed, providing privacy and security for sensitive content. In PDF documents, redaction is crucial for maintaining compliance with data protection regulations like GDPR, HIPAA, and other privacy standards. IronPDF provides reliable redaction capabilities that go beyond simple text overlay, ensuring that sensitive data is permanently removed from the PDF structure.

Similarly, redacting a region obscures specified areas in the document. This requires providing the region's coordinates, width, and height. Region redaction is particularly useful when dealing with forms, signatures, images, or any visual content that contains sensitive information. Unlike simple text redaction, region-based redaction allows developers to target specific areas of a document regardless of the content type.

Quickstart: Redact Sensitive Text in PDFs

Remove sensitive information from PDF documents using IronPDF's redaction methods. Redact text on all PDF pages with just a few lines of code, ensuring confidentiality and compliance. This guide demonstrates loading a PDF, applying redaction, and saving the updated document using IronPDF's API.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    IronPdf.PdfDocument doc = IronPdf.PdfDocument.FromFile("document.pdf");
    doc.RedactTextOnAllPages("sensitive info");
    doc.SaveAs("redacted_document.pdf");
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

How Do I Redact Text from PDFs in C#?

Text redaction is straightforward with IronPDF. Use the RedactTextOnAllPages method to remove a specified phrase from the entire document. Let's use a PDF example document.

using IronPdf;

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

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

pdf.SaveAs("redacted.pdf");

For more advanced PDF manipulation capabilities, you can explore how to edit PDFs or learn about setting PDF permissions and passwords to enhance document security alongside redaction.

What Does the Redacted PDF Look Like?

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.

What Parameters Control Text Redaction?

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 "*".

Here's a more comprehensive example showing how to use these parameters:

using IronPdf;

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

// Redact with custom parameters
pdf.RedactTextOnAllPages("SSN: 123-45-6789", 
    CaseSensitive: true, 
    OnlyMatchWholeWords: false, 
    DrawRectangles: true, 
    ReplacementText: "[REDACTED]");

// Redact multiple sensitive items
string[] sensitiveTerms = { "salary", "password", "credit card" };
foreach (string term in sensitiveTerms)
{
    pdf.RedactTextOnAllPages(term, CaseSensitive: false);
}

pdf.SaveAs("fully_redacted_report.pdf");

For handling documents with complex formatting, consider reviewing how to manage fonts to ensure proper text recognition during redaction.


My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

How Do I Redact Specific Regions in PDFs?

Redacting specific regions in documents is highly effective. 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.

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");

Advanced Region Redaction Examples

When working with complex documents, you may need to redact multiple regions or calculate coordinates dynamically:

using IronPdf;
using IronSoftware.Drawing;
using System.Collections.Generic;

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

// Redact multiple regions
List<RectangleF> regionsToRedact = new List<RectangleF>
{
    new RectangleF(100, 200, 200, 50),  // Signature area
    new RectangleF(100, 300, 200, 100), // Address block
    new RectangleF(350, 150, 150, 150)  // Photo ID area
};

foreach (var region in regionsToRedact)
{
    pdf.RedactRegionsOnAllPages(region);
}

// Redact regions on specific pages only
pdf.RedactRegionOnPage(0, new RectangleF(50, 50, 100, 30)); // Page 1 header
pdf.RedactRegionOnPages(new[] { 2, 3, 4 }, new RectangleF(400, 700, 150, 50)); // Footer on pages 3-5

pdf.SaveAs("form_redacted.pdf");

What Does Region Redaction Look Like?

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

What Happens to Images Under a Redacted Region?

IronPDF 2026.11.1+ introduces pixel-level image redaction: region redaction sets the image pixels under the region to black, including images with masks or alternates and images inside forms, except in the cases listed below. Before that, the black box was drawn over an image and its original pixels stayed in the file, where they could still be extracted. For compliance-sensitive redaction, where a silently skipped image is not acceptable, set ThrowOnUnredactedImages to true.

using IronPdf;
using IronPdf.Exceptions;
using IronSoftware.Drawing;

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

// Region covering the photo on the first page
RectangleF photoArea = new RectangleF(395, 565, 130, 165);

try
{
    // Redact the photo and fail on any unredacted image
    pdf.RedactRegionOnPage(0, photoArea, ThrowOnUnredactedImages: true);
    pdf.SaveAs("redactedImage.pdf");
}
catch (IronPdfProductException ex)
{
    // An image under the region still contains its original data
    Console.WriteLine(ex.Message);
}
C#

The rest of the region is redacted before the IronPdfProductException is thrown. RedactRegionsOnPage, RedactRegionOnPages and RedactRegionsOnAllPages take the same flag, and the multi-page methods redact every page before they throw.

Please note: RedactRegionOnPages ignores duplicate page indexes and skips indexes beyond the page count.

The result PDF below is from redacting the photo on an employee record.

Images that cannot be redacted safely keep their original data, log a warning, and make the flag throw:

  • Images placed with a shear
  • Stencil masks (/ImageMask) drawn as the image itself
  • Inline images and images with a color-key mask
  • Images whose mask stream, or whose containing form stream, another placement also draws
  • Images with an alternate that is shared with another object or has its own mask
  • Images whose soft mask has /Matte, or a /Decode other than [0 1] and [1 0]
  • Images in forms nested deeper than 16 levels, and image formats that cannot be decoded
  • Any image redacted while change tracking is enabled, because the earlier revision keeps the original image data

Images in annotation appearance streams, tiling patterns and Type 3 glyphs are not redacted and not counted, so they raise no warning and no exception.

What else region redaction changes:

  • Images stored as DCT, JPX, CCITT, Indexed, CMYK or ICCBased are re-encoded as Flate/DeviceRGB, so the file size can grow
  • A JPEG 2000 image with its own transparency becomes opaque across the whole image, not only the redacted area
  • Kept parts of text drawn in a stroking mode, such as synthetic bold, are redrawn as plain filled text
  • Kept parts of invisible text, such as an OCR text layer, stay invisible

Shared images: when another placement draws the same image, the redacted placement gets its own copy; when a copy is not possible, the image is redacted in place, every placement shows the redaction, and a warning is logged

IronPDF writes these warnings to its log, which is off by default; custom logging routes them to your own logger. The troubleshooting page for this warning covers its common causes, including signed PDFs.

Please note: In IronPdfEngine or Docker deployments, match the engine version to the library version. An older engine cannot redact image data: it logs a warning once per process, and the ThrowOnUnredactedImages overloads throw when the flag is true.

When Should I Use Region vs Text Redaction?

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

Region redaction is ideal when:

  • You need to remove images, logos, or graphical elements
  • The sensitive content includes handwritten notes or signatures
  • You're dealing with forms where the layout is fixed
  • You want to redact entire sections regardless of text content

Text redaction is better when:

  • You're searching for specific keywords or phrases
  • The content to redact appears in multiple locations
  • You need case-sensitive or whole-word matching
  • The document structure may vary between files

For comprehensive PDF security, combine redaction with other security features. Learn more about signing PDFs and explore PDF compression to optimize your secured documents.

Best Practices for PDF Redaction

When implementing redaction in your applications:

  1. Always save to a new file: Never overwrite the original document to maintain an audit trail
  2. Verify redaction completeness: Review the output to ensure all sensitive data is removed
  3. Consider metadata: Remember to also edit and remove metadata that might contain sensitive information
  4. Test coordinate calculations: When using region redaction, test your coordinate calculations across different page sizes and orientations

For additional document processing needs, explore how to extract text and images from PDFs before applying redaction, or learn about creating PDF forms with built-in privacy controls.

Ready to see what else you can do? Check out our tutorial page here: Edit PDFs

Frequently Asked Questions

What is PDF text redaction in IronPDF?

In IronPDF, text redaction involves permanently removing or obscuring sensitive information from PDFs, ensuring privacy and compliance by covering content with black boxes or replacement text.

How can I redact sensitive text on all pages of a PDF using C#?

You can use the RedactTextOnAllPages method in IronPDF to remove specified phrases from an entire document efficiently, as demonstrated in their C# redaction guide.

What are the main parameters of the text redaction methods in IronPDF?

The main parameters include ReplaceText, CaseSensitive, OnlyMatchWholeWords, DrawRectangles, and ReplacementText, each defining aspects of how text is redacted.

When should I use region redaction instead of text redaction?

Region redaction is ideal for removing images, logos, or sections containing handwritten notes or fixed layouts. Text redaction is better for removing specific phrases appearing in multiple locations.

Can IronPDF redact regions from a document?

Yes, IronPDF can redact specific regions in a document using the RedactRegionsOnAllPages method, which is useful for targeting areas with sensitive images or notes.

Does IronPDF provide a way to redact multiple regions in a PDF file?

Yes, you can redact multiple regions in a PDF using a list of RectangleF objects, allowing for precise control over which areas to obscure.

How does IronPDF ensure compliance with privacy regulations?

IronPDF's redaction features help ensure compliance by permanently removing sensitive data from PDFs, aligning with regulations like GDPR and HIPAA.

What is the process for redacting sensitive information from a PDF with IronPDF?

The process involves downloading the C# library, preparing the PDF, applying redaction methods like RedactTextOnAllPages, and saving the document as a new file.

What are the benefits of using IronPDF for redacting sensitive information?

IronPDF offers reliable redaction features beyond simple text overlay, ensuring sensitive data is removed from the PDF structure, providing reliable privacy and security.

How can IronPDF assist with compliance beyond redaction?

In addition to redaction, IronPDF can manage PDF permissions, edit metadata, and apply encryption, aiding comprehensive compliance and security strategies.

Does region redaction remove the image pixels under the region?

Yes. RedactRegionOnPage and the other region methods set the image pixels under the region to black. Images that cannot be redacted safely keep their original data, and IronPDF logs a warning.

How do I make region redaction fail when an image could not be redacted?

Pass ThrowOnUnredactedImages: true to a region redaction method. It redacts the rest of the region first, then throws an IronPdfProductException if an image still contains its original data.

Which images does IronPDF leave unredacted under a region?

Images placed with a shear, inline images, stencil masks, color-key masks, undecodable formats and any image redacted while change tracking is enabled keep their original data and are reported.

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.

Read More

Ready to Get Started?

NuGet Downloads 22,321,142Version:2026.11just released