PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2008 VS 2005 CLR 2.0

PDF Text Redaction Using PDFOne .NET

Removing unwanted text from a document.
By V. Subhash

In Version 4 of PDFOne .NET, we have introduced text redaction. You can redact text by specifying a region to be redacted. You can also provide a text string whose occurrences in the document can be redacted. The text string can be a literal search text or it can be a regular expression. In this article, we will see examples of both.

Simple Text Redaction

The following code snippet shows how to perform simple text redaction using literal search text.

PDFDocument PDFDocument1 = new PDFDocument("your-license-key");

// Load PDF document
PDFDocument1.Load("sample_doc1.pdf");

PDFDocument1.RedactText(
    // redact in page with number
    1,
    // redact text matching "gnostice"
    "gnostice",
    // search for literal matches
    PDFSearchMode.LITERAL,
    // match all cases and instances
    PDFSearchOptions.NONE,
    // stroke redacted regions in red color
    new Pen(Color.Red),
    // fill redacted region in lime color
    new SolidBrush(Color.Lime),
    // enable stroking of redacted regions
    true,
    // enable filling of redacted regions
    true);

PDFDocument1.Save("redacted_doc1.pdf");

// Close the document
PDFDocument1.Close();
Original Document and the Redacted Version

Advanced Text Redaction

You can also use regular expressions with the redactText method. I have modified the above code snippet so that it will redact all phone numbers, like this:

PDFDocument1.RedactText(
  // redact in page with number 2
  17,
  // redact phone numbers
  @"\(\d{3}\)\s\d{3}-\d{4}",
  // search for regular expression matches
  PDFSearchMode.REGEX,
  // match all cases and instances
  PDFSearchOptions.NONE,
  // stroke redacted regions in red color
  new Pen(Color.Red),
  // fill redacted region in lime color
  new SolidBrush(Color.Lime),
  // enable stroking of redacted regions
  true,
  // enable filling of redacted regions
  true);
Original Document and the Redacted Version

---o0O0o---

Our Developer Tools
eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers

PDFOne (for Java™)

A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications.

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

Privacy | Legal | Feedback | Newsletter | Resellers © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved.

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).