How to Redact Text and Regions in PDFs Using IronPDF and C#
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 robust 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.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
IronPdf.PdfDocument doc = IronPdf.PdfDocument.FromFile("document.pdf"); doc.RedactTextOnAllPages("sensitive info"); doc.SaveAs("redacted_document.pdf");Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download the C# library to redact text and regions
- Prepare the PDF document for redaction
- Use the
RedactTextOnAllPagesmethod to redact text on the entire document - Use the
RedactRegionsOnAllPagesmethod to redact regions on every page of the document - Save or export the PDF document as a new document
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.
:path=/static-assets/pdf/content-code-examples/how-to/redact-text-redact-text.csusing 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");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.
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.
:path=/static-assets/pdf/content-code-examples/how-to/redact-text-redact-region.csusing 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");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.
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:
- Always save to a new file: Never overwrite the original document to maintain an audit trail
- Verify redaction completeness: Review the output to ensure all sensitive data is removed
- Consider metadata: Remember to also edit and remove metadata that might contain sensitive information
- 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 and why is it important?
PDF text redaction is the process of permanently removing or obscuring sensitive information from documents by covering text with black boxes or deleting it entirely. IronPDF provides robust redaction capabilities that ensure sensitive data is permanently removed from the PDF structure, helping maintain compliance with data protection regulations like GDPR and HIPAA.
How do I redact specific text from all pages in a PDF?
Using IronPDF, you can redact specific text from all pages with the RedactTextOnAllPages method. Simply load your PDF document, call doc.RedactTextOnAllPages('sensitive info'), and save the redacted document. This permanently removes the specified text throughout the entire PDF.
Can I redact specific regions or areas in a PDF document?
Yes, IronPDF allows you to redact specific regions by providing coordinates, width, and height using the RedactRegionsOnAllPages method. This is particularly useful for obscuring forms, signatures, images, or any visual content containing sensitive information, regardless of content type.
What's the difference between text redaction and region redaction?
Text redaction in IronPDF targets and removes specific text strings throughout the document, while region redaction obscures specified areas based on coordinates. Region redaction is ideal for non-text content like images, signatures, or form fields, while text redaction is perfect for removing specific words or phrases.
How many steps are required to implement PDF redaction?
IronPDF makes PDF redaction simple with just 5 steps: download the C# library, prepare your PDF document, use RedactTextOnAllPages for text redaction or RedactRegionsOnAllPages for region redaction, and finally save the redacted document as a new file.
Is the redaction process permanent and secure?
Yes, IronPDF's redaction methods permanently remove sensitive information from the PDF structure, not just visually covering it. This ensures that redacted content cannot be recovered or accessed, providing true security and compliance for sensitive documents.






