com.groupdocs.redaction.redactions

Class ExactPhraseRedaction



  • public class ExactPhraseRedaction
    extends TextRedaction

    Represents a text redaction that replaces exact phrase in the document's text, case insensitive by default.


    Learn more

    The following example demonstrates performing case-sensitive phrase search and replacement.

    try (Redactor redactor = new Redactor("C:\\sample.pdf"))
     {
       // By default, the second parameter, isCaseSensitive = false;
       doc.apply(new ExactPhraseRedaction("John Doe", true, new ReplacementOptions("[personal]")));
       doc.save();
     }
      

    The following example demonstrates replacing phrase (case insensitive) with solid red rectangle.

    try (Redactor redactor = new Redactor("C:\\sample.pdf"))
     {
       // By default, isCaseSensitive = false;
       doc.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Red)));
       doc.save();
     }
      
    • Constructor Detail

      • ExactPhraseRedaction

        public ExactPhraseRedaction(String searchPhrase,
                            ReplacementOptions options)

        Initializes a new instance of ExactPhraseRedaction class in case insensitive mode.

        Parameters:
        searchPhrase - String to search and replace
        options - Replacement options (textual, color)
      • ExactPhraseRedaction

        public ExactPhraseRedaction(String searchPhrase,
                            boolean isCaseSensitive,
                            ReplacementOptions options)

        Initializes a new instance of ExactPhraseRedaction class.

        Parameters:
        searchPhrase - String to search and replace
        isCaseSensitive - True if case sensitive search is required
        options - Replacement options (textual, color)
    • Method Detail

      • getSearchPhrase

        public final String getSearchPhrase()

        Gets the string to search and replace.

        Returns:
        The string to search and replace.
      • isCaseSensitive

        public final boolean isCaseSensitive()

        Gets a value indicating whether the search is case-sensitive or not.

        Returns:
        A value indicating whether the search is case-sensitive or not.
      • getDescription

        public String getDescription()

        Returns a string, describing the redaction and its parameters.

        Overrides:
        getDescription in class Redaction
        Returns:
        Text, containing redaction name and parameters.
      • applyTo

        public RedactorLogEntry applyTo(DocumentFormatInstance formatInstance)

        Applies the redaction to a given format instance.

        Specified by:
        applyTo in class Redaction
        Parameters:
        formatInstance - An instance of a document to apply redaction
        Returns:
        Status of the redaction: success/failure and error message if any