Cómo redactar texto y regiones en PDF usando C#

How to Redact Text and Regions

This article was translated from English: Does it need improvement?
Translated
View the article in English

Redacting text involves permanently removing or obscuring sensitive or confidential information from a document. This is usually 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.

Quickstart: Redact Sensitive Text in PDFs

Effortlessly remove sensitive information from PDF documents using IronPDF's simple redaction methods. With just a few lines of code, developers can redact text on all pages of a PDF, ensuring confidentiality and compliance. This quick guide demonstrates how to load a PDF, apply redaction, and save the updated document, all with IronPDF's intuitive API.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

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

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


Redact Text Example

Text redaction can be easily accomplished with the help of 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.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.

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

Preguntas Frecuentes

¿Cuál es el proceso para redactar texto en PDFs?

Redactar texto en PDFs implica usar métodos como RedactTextOnAllPages en IronPDF, lo que le permite eliminar u ocultar texto específico en todo un documento para garantizar privacidad y seguridad.

¿Cómo redacto una región específica en un documento PDF?

Puede redactar una región específica en un PDF usando el método RedactRegionsOnAllPages de IronPDF. Esto requiere especificar las coordenadas, ancho y alto del área que desea redactar usando un objeto RectangleF.

¿Puedo redactar texto de solo una página de un PDF?

Sí, puede usar el método RedactTextOnPage en IronPDF para redactar texto de una sola página dentro de un documento PDF.

¿Cuáles son los parámetros disponibles para la redacción de texto en PDFs?

IronPDF ofrece parámetros como ReplaceText, CaseSensitive, OnlyMatchWholeWords, DrawRectangles y ReplacementText para personalizar el proceso de redacción según sus necesidades.

¿Cómo puedo asegurarme de que solo se redacten palabras completas en un PDF?

IronPDF proporciona el parámetro OnlyMatchWholeWords que, cuando se establece en verdadero, asegura que solo se redacten palabras completas en el documento PDF.

¿Es posible usar un texto de reemplazo personalizado para el contenido redactado?

Sí, IronPDF le permite especificar texto de reemplazo personalizado usando el parámetro ReplacementText, siendo el predeterminado un asterisco (*).

¿Cómo maneja IronPDF la sensibilidad de mayúsculas y minúsculas durante la redacción de texto?

IronPDF utiliza el parámetro CaseSensitive, que se puede establecer en verdadero si desea que la redacción de texto sea sensible a mayúsculas, coincidiendo exactamente con las letras.

¿Qué métodos están disponibles para redactar múltiples páginas en un PDF?

Para redactar múltiples páginas, IronPDF proporciona los métodos RedactTextOnPages y RedactRegionOnPages, permitiendo especificar rangos o páginas específicas para la redacción.

¿IronPDF es compatible con .NET 10 para las funciones de redacción de texto?

Sí, IronPDF es compatible con .NET 10 de fábrica, incluyendo todos los métodos de redacción como RedactTextOnAllPages , RedactTextOnPages y RedactRegionsOnAllPages . Puede usar IronPDF en proyectos .NET 10 sin necesidad de configuraciones especiales ni soluciones alternativas.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado