Skip to main content
All docs
V26.1
  • RedactionAnnotation Class

    A redaction annotation.

    Namespace: DevExpress.Docs.Pdf

    Assembly: DevExpress.Docs.Pdf.v26.1.dll

    Declaration

    public class RedactionAnnotation :
        MarkupAnnotation

    Example

    How to: Create a Redaction Annotation

    The following code snippet creates redaction annotations over the search results and saves the document to a new file:

    using DevExpress.Docs.Pdf;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"C:\Documents\document_001.pdf"))) {
        string[] search = {
            "Maria Anders", "030-0074321",
            "alfredsfutterkiste@mail.com"
        };
        foreach (string word in search) {
            IEnumerable<TextSearchInfo> results =
                pdfDocument.FindText(word, new TextSearchOptions(true, true));
            foreach (TextSearchInfo searchResult in results) {
                var page = pdfDocument.Pages[searchResult.PageIndex];
                var rects = searchResult.Matches
                    .SelectMany(x => x.MatchFragments)
                    .Select(x => x.Rectangle);
                // Create a redaction annotation.
                var redactionAnnotation =
                    new RedactionAnnotation(rects);
    
                redactionAnnotation.Color = PdfColor.Black;
                redactionAnnotation.FillColor = PdfColor.Red;
    
                redactionAnnotation.OverlayText = "Classified";
                redactionAnnotation.TextJustification =
                    TextJustification.Centered;
                redactionAnnotation.RepeatText = false;
                page.Annotations.Add(redactionAnnotation);
            }
        }
    
        // Save the document with the redaction annotation.
        using (FileStream stream =
            File.Create("UpdatedDocument.pdf"))
        {
            pdfDocument.Save(stream);
        }
    }
    

    Implements

    Inheritance

    See Also