XDoc.PDF
Features
Tech Specs
How-to C#
Pricing
How to Start Convert PDF Read PDF Build PDF 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 select, 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










  • 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. Call the Redact SDK API to remove or redact sensitive text that is visible in a PDF.







Redact all characters in a page region using c#


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