Skip to main content
All docs
V25.1
  • Manage Redaction Annotations in DevExpress PDF Document API

    • 6 minutes to read

    Redaction annotations are tools used to remove sensitive or confidential information from a document. These annotations allow users to mark areas of text, images, or other content for redaction.

    pdf document api redacted document

    PDF Document API allows you to create, delete, and flatten annotations, edit their content, and add related comments and reviews. You can implement the following scenarios:

    Create redaction annotations and save the document
    You can send the result for review. The recipient can approve or comment on the redaction annotations before applying them.
    Load a document with redaction annotations and inspect redacted areas
    Obtain annotations, review or change the required parameters, and apply or remove redaction annotations if necessary.
    Create and apply all redaction annotations in your PDF document
    Load a document with redaction annotations or create annotations in code, and apply these annotations. Once applied, the redacted content is removed so that the information cannot be recovered or viewed by unauthorized viewers.

    This topic contains detailed information on redaction annotations. Refer to the following help topic for more information on all annotations and their common features: Annotations in PDF Documents.

    Create Redaction Annotations and Save the Document

    The PdfPageFacade.Annotations property retrieves all page annotation properties. Use the PdfDocumentFacade.Pages property to access the PdfPageFacade class.

    Use the PdfPageFacade.AddRedactAnnotation method to create a redaction annotation. When adding a redaction, you can specify multiple areas on the page (redact information from multiple places simultaneously).

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

    Load a Document with Redaction Annotations and Inspect Redacted Areas

    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.

    The following code snippet obtains all redaction annotations, and adds an “approved” review to all annotations from a specific author:

    pdf document api redaction annotations add review

    using DevExpress.Pdf;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("output_to_review.pdf");
    
        // Access the first page's properties
        PdfPageFacade page = processor.DocumentFacade.Pages[0];
    
        // Retrieve all redaction annotations
        var redactAnnotations = page.Annotations.Where
          (annotation => annotation.Type == PdfAnnotationType.Redaction);
    
        // Change annotation parameters
        foreach (PdfRedactAnnotationFacade redaction in redactAnnotations)
        {
            if(redaction.Author == "Jane Doe")
                redaction.AddReview("Nancy Skywalker", PdfAnnotationReviewStatus.Accepted);
        }
        processor.SaveDocument("output_approved.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's 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");
    }
    

    Note

    When you call one of the Flatten… methods for redaction annotations, their overlay parameters (text, fill color, and so on) are not applied and the redacted content is not removed. Use one of the ApplyRedactAnnotations methods to apply these annotations.

    Apply Redaction Annotations

    You can apply a single redaction annotation, annotations on a specific page, or annotations in 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.

    Once the redaction annotation is applied, it can no longer 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");
    }