PM > Install-Package XDoc.PDF

How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Text Redact Library
How to find, redact, remove text content from PDF file using c# .net


C# Demo Code for Redacting PDF Text to Protect Your PDF Document in C#.NET Project





In this tutorial, you learn how to search, find, redact text on PDF document in C#.

How to redact, remove text content from existing PDF file using C#

  1. Download XDoc.PDF Redact C# library
  2. Install C# library to redact, remove text from PDF document
  3. Step by Step Tutorial








  • Best .NET PDF document manipulation SDK control for PDF text content protecting in Visual C#.NET project
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Evaluation library and components for blanking out PDF text in C#.NET WinForms and ASP.NET WebForm application
  • Free online C# source code to erase text from adobe PDF file in Visual Studio. NET class without adobe reader installed
  • Provide a best and easy way to darken text in PDF document in C#.NET framework program
  • Enable users abilities to adjust color and transparency while scraping text from PDF file
  • Able to redact selected text in PDF document


Before you distribute a PDF, you may want to examine the document for sensitive content or private information that can trace the document to you. Use the PDF C# library redaction API to remove or redact sensitive text that is visible in a PDF.





Redact all characters in a page region using c#


Redaction is the process of permanently removing visible text and graphics from a PDF document. The following C# sample code explains how to redact an area from the PDF page.



String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

//  open document
PDFDocument doc = new PDFDocument(inputFilePath);
//  get the 3rd page
PDFPage page = (PDFPage)doc.GetPage(2);
//  set redact region
RectangleF region = new RectangleF(100F, 100F, 300F, 300F);

//  create redaction option
RedactionOptions options = new RedactionOptions();
options.AreaFillColor = Color.Black;

//  process redaction
PDFTextHandler.RedactText(page, region, options);
//  output file
doc.Save(outputFilePath);




Redact page content with overlay text using c#


String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

//  open file and get the first page
PDFDocument doc = new PDFDocument(inputFilePath);
int pageIndex = 0;
PDFPage page = (PDFPage)doc.GetPage(pageIndex);

//  set the redact region
RectangleF redactRegion = new RectangleF(10F, 10F, 400F, 300F);

RedactionOptions ops = new RedactionOptions();
//  set redect fill color: black
ops.AreaFillColor = Color.Black;
//  enable overlay text
ops.EnableOverlayText = true;
//  set overlay message
ops.OverlayText = @"Confidential";
//  set font of the overlay text
ops.OverlayTextFont = new Font("Arial", 8F, FontStyle.Regular);
//  set color of the overlay text
ops.OverlayTextColor = Color.Red;
//  center alignment for the overlay message
ops.OverlayTextAlignment = OverlayTextAlignment.Center;
//  repeat the message to fill the whole redect region
ops.IsRepeat = true;
//  use the font size given above
ops.IsAutoSize = false;

//  apply redaction
PDFTextHandler.RedactText(page, redactRegion, ops);

doc.Save(outputFilePath);




Redact contents in the given area of a page using c#


String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

//  open file and get the first page
PDFDocument doc = new PDFDocument(inputFilePath);
int pageIndex = 0;
PDFPage page = (PDFPage)doc.GetPage(pageIndex);

//  set a redact area start from point (200, 300) with size (200, 150)
//  all value in pixels (96 dpi)
RectangleF redactArea = new RectangleF(200, 300, 200, 150);

//  use default redact options
RedactionOptions ops = new RedactionOptions();

//  apply redaction for the whole page
page.Redact(redactArea, ops);

doc.Save(outputFilePath);




Add redact annotation using c#


The following source code will help you add redaction annotations to the pdf pages. Redaction annotations will not remove the redacted content from the pdf file. You need use PDF reader/writer software (such as Acrobat Pro) to apply the redactions.



String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_1.pdf";

//  open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
//  get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);

//  create the annotation
PDFAnnotRedact redactAnnot = new PDFAnnotRedact();

//  set Redact region (in 96 dpi)
redactAnnot.Boundary = new RectangleF(10, 10, 100, 200);
//  set background color of the redact area to red
redactAnnot.FillColor = Color.Red;
//  set border color of the redact area to green
redactAnnot.BorderColor = Color.Green;
//  set Redact options
//  Set area fill color (while mouse enter)
redactAnnot.Options.AreaFillColor = Color.Yellow;
//  disable overlay text
redactAnnot.Options.EnableOverlayText = false;

//  add annotation to the page
PDFAnnotHandler.AddAnnotation(page, redactAnnot);

//  save to a new file
doc.Save(outputFilePath);








Common Asked Questions

Is redaction permanent in PDFs?

After the redactions in PDF have been applied, the PDF editor applications will permanently remove the text, image and other information from the PDF document after saved. Using C# PDF redaction library, you can mark all the redactions you need and apply to permanently delete all redactions from the PDF document in C# ASP.NET Core MVC web and Windows Forms applications.

How do you black out text in a PDF?

There are two ways to remove text from a PDF file. One is deleting them through PDF content editing function. The other is redacting the specified text from PDF document permanently. Using RasterEdge XDoc.PDF C# library, you can delete text content directly from the PDF pages, or mark them to redact and apply redaction on the PDF file using C# codes in Visual Studio .NET projects.

Why can't I redact text in PDF?

If your PDF document is a digitally signed PDF file, you cannot apply redaction to remove text from it. Using C# PDF library, you can quickly add a digital signature on the PDF document to prevent users to redact, modify the document in C# web and desktop apps.

How to black out text in PDF without Adobe Acrobat?

There are many free online tools or desktop PDF editing tools to support PDF document text redaction without Acrobat installed. You can also build a simple PDF text redaction tool using XDoc.PDF C# library, or use EdgePDF asp.net web pdf editor demo app to black out text from PDF file.

How to remove text from PDF without Adobe?

You can remove or delete searched or specified text from PDF file using PDF editing tools (online or desktop version). Using RasterEdge C# PDF library, you can quickly remove multiple searched text results from a PDF file in your C# WPF or WinForms applications.

What's the difference between editing and redacting?

Redacting text is removing or blacking out sensitive text information from an existing PDF document. It usually will keep redacted text space. Editing text including text deleting is the process of working on a PDF document to improve content structure. It usually will not keep the deleted text space. Using RasterEdge C# PDF library, you can search and find the texts and delete or redact them from the PDF file in your C# asp.net, mvc, web or Windows applications.

How do you repeat redaction mark across pages?

Most PDF editing programs support repeat text redaction on a PDF file. You usually mark the first text redaction, and repeat them by right clicking. Using C# PDF library, you can do batch text redaction on the PDF document in your Visual Studio .NET projects.