Skip to main content
All docs
V25.1
  • PdfRedactAnnotationFacade Class

    Contains members used to manage redaction annotations without access to their inner structure.

    Namespace: DevExpress.Pdf

    Assembly: DevExpress.Pdf.v25.1.Core.dll

    NuGet Package: DevExpress.Pdf.Core

    Declaration

    public class PdfRedactAnnotationFacade :
        PdfMarkupAnnotationFacade

    Remarks

    Create Redaction Annotations

    Use the PdfPageFacade.AddRedactAnnotation method to create a redaction annotation. You can create an annotation in a single or multiple page areas.

    The following code snippet searches for specific words and creates redaction annotations over them:

    pdf document api redaction annotations create

    using DevExpress.Pdf;
    
    PdfDocumentProcessor pdfProcessor = new PdfDocumentProcessor();
    pdfProcessor.LoadDocument("..\\..\\Invoice.pdf");
    
    PdfDocumentFacade documentFacade = pdfProcessor.DocumentFacade;
    
    PdfTextSearchParameters searchParameters =
      new PdfTextSearchParameters();
    searchParameters.CaseSensitive = true;
    searchParameters.WholeWords = true;
    
    string[] search = new string[] { "Maria Anders", "030-0074321", "alfredsfutterkiste@mail.com" };
    foreach (string word in search)
    {
        PdfTextSearchResults results = pdfProcessor.FindText(word, searchParameters);
    
        // If the text is found, create an annotation
        if (results.Status == PdfTextSearchStatus.Found) {
            var pageIndex = results.Page.GetPageIndex();
            PdfRedactAnnotationFacade redactAnnotation =
                documentFacade.Pages[pageIndex].AddRedactAnnotation(results.Rectangles);
            redactAnnotation.Author = "Jane Doe";
    
            // Set the redaction annotation appearance
            redactAnnotation.FontColor = new PdfRGBColor(0, 0, 0);
            redactAnnotation.FillColor = new PdfRGBColor(1, 1, 1);
            redactAnnotation.FontName = "Arial";
            redactAnnotation.FontSize = 0; // Enables font auto-size
            redactAnnotation.OverlayText = "Classified";
            redactAnnotation.TextJustification = PdfTextJustification.Centered;
            redactAnnotation.RepeatText = false;   
        }
    }
    // Save the document with the redaction annotation
    // and send it for review
    pdfProcessor.SaveDocument("output_to_review.pdf");
    

    Edit Redaction Annotations

    The PdfPageFacade.Annotations property returns all page annotation properties. You can filter redaction annotation properties, cast them to the PdfRedactAnnotationFacade class, and use class properties to change annotation parameters.

    using DevExpress.Pdf;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("output_to_review.pdf");
    
        // Access the first page properties
        PdfPageFacade page = processor.DocumentFacade.Pages[0];
    
        // Retrieve all redact annotations
        var redactAnnotations = page.Annotations.Where
          (annotation => annotation.Type == PdfAnnotationType.Redaction);
    
        // Change annotation parameters
        foreach (PdfRedactAnnotationFacade redaction in redactAnnotations)
        {
            redaction.OverlayText = "Redacted";
            redaction.FillColor = new PdfRGBColor(1, 0.94, 0);
        }
        processor.SaveDocument("output_to_review.pdf");
    }
    

    Remove Redaction Annotations

    Call the PdfAnnotationFacade.Remove() method to remove an annotation.

    The following code snippet removes all redaction annotations on the first page:

    using DevExpress.Pdf;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
    
        // Load a document
        processor.LoadDocument("Invoice.pdf");
    
        // Access the first page properties 
        PdfPageFacade page = processor.DocumentFacade.Pages[0];
    
        // Retrieve all rubber stamps
        var redactAnnotations = page.Annotations.Where
          (annotation => annotation.Type == PdfAnnotationType.Redaction).ToList();
    
        // Remove all rubber stamps
        foreach (PdfRedactAnnotationFacade redaction in redactAnnotations)
        {
            redaction.Remove();
        }
        processor.SaveDocument("output_deleted.pdf");
    }
    

    Apply Redaction Annotations

    You can apply a single redaction annotation, annotations on a specific page or an entire document. The following methods are available:

    Each method allows you to specify what content type to keep visible in the redaction area. Create the PdfClearContentOptions object, set one of the Clear... properties to false to specify the content type to keep visible, and pass this object as the Apply... method parameter. If the options parameter is not specified, all content is redacted.

    When the annotation is applied, it is no longer can be obtained, edited or removed.

    The following code snippet applies redaction annotations made by a specific author:

    pdf document api redaction annotations apply

    using DevExpress.Pdf;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
    
        processor.LoadDocument("output_to_review.pdf");
        PdfDocumentFacade documentFacade = processor.DocumentFacade;
    
        foreach (var page in documentFacade.Pages)
        {
            var redactionAnnotations = page.Annotations.Where(annotation => annotation.Type == PdfAnnotationType.Redaction).ToList();
            foreach (PdfRedactAnnotationFacade annotation in redactionAnnotations)
            {
                if (annotation.Author == "Jane Doe")
                    annotation.Apply();
            }
        }
        processor.SaveDocument("output_applied.pdf");
    }
    

    Inheritance

    See Also