DEV Community

Derek
Derek

Posted on

How to Permanently Delete Your Sensitive Information? - C#

With the rapid development of technology, paperless offices have become mainstream. Among various document formats, PDF stands out as the preferred choice for digital workflows, thanks to its ability to maintain consistent display across different devices.

However, as information and data breaches become increasingly common, document data security has drawn growing attention — and this is where redaction plays a vital role.

In this article, we’ll explore how to implement PDF redaction in C#, helping you protect confidential information and prevent unintentional data exposure.

What Is PDF Redaction?

PDF redaction refers to the process of permanently removing content—such as text, data, or images—from a PDF file. Because the redacted content cannot be recovered, redaction is one of the most secure methods to safeguard highly sensitive information.

How to Apply PDF Redaction in C#

ComPDF provides several ways to protect your sensitive information, including PDF redaction, encryption, and more.

Select the Area to Redact

A basic method involves selecting and marking specific areas in the PDF that you want to redact.
For example, you can create a redaction annotation to cover a designated area on the first page of the document.

CPDFDocument document = CPDFDocument.InitWithFilePath("filePath");
CPDFPage page = document.PageAtIndex(0);
CPDFRedactAnnotation redact = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_REDACT) as CPDFRedactAnnotation;
redact.SetRect(new CRect(0, 50, 50, 0));
redact.SetOverlayText("REDACTED");

CTextAttribute textDa = new CTextAttribute();
textDa.FontName = "Helvetica";
textDa.FontSize = 12;
byte[] fontColor = { 255, 0, 0 };
textDa.FontColor = fontColor;
redact.SetTextDa(textDa);

redact.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_LEFT);
byte[] fillColor = { 255, 0, 0 };
redact.SetFillColor(fillColor);
byte[] outlineColor = { 0, 255, 0 };
redact.SetOutlineColor(outlineColor);

redact.UpdateAp();
Enter fullscreen mode Exit fullscreen mode

In addition, ComPDF also supports:

  • Searching for and redacting specific text or fields,
  • Editing or redacting specific pages, or
  • Applying redaction to the entire document.

For more details, please refer to our Original Blog >>.

Top comments (0)