GroupDocs.Redaction for .NET 25.3 Release Notes

Major Features

There are the following improvements in this release:

  • Fixed problems with rasterization to PDF A1A.
  • Implemented custom redaction handler for PDF PageArea redactions.

Full List of Issues Covering all Changes in this Release

KeySummaryCategory
REDACTIONNET-593Rasterization to PDF A1A problemsBug
REDACTIONNET-594Implement custom text redactionsFeature

Public API and Backward Incompatible Changes

Public API changes

The ICustomRedactionHandler interface for custom redaction implementations has been added to the GroupDocs.Redaction.Redactions namespace.
The CustomRedactionContext class, which provides document content for custom redactions, has been added added to the GroupDocs.Redaction.Redactions namespace.
The CustomRedactionResult class, which contains the result of custom redactions, has been added to the GroupDocs.Redaction.Redactions namespace.
The CustomRedaction property, which allows getting and setting a custom redaction handler, has been added to the GroupDocs.Redaction.Redactions.ReplacementOptions class.

Usage

The main purpose of custom redaction handlers is to give customers greater flexibility and efficiency in the document redaction process.

C#


// The following example demonstrates how to use custom redaction, including AI-powered redactions.  
// You can provide a custom redaction handler to control the processing of each text segment in the document.  
// Currently, this feature is only supported for PDFs. 

            // Use a regular expression to process the entire text within a custom handler.
            Regex regex = new Regex(".*");

            // Define replacement options.
            ReplacementOptions optionsText = new ReplacementOptions("[replaced]");
            // Set up the custom redaction handler.
            optionsText.CustomRedaction = new TextRedactor();

            var textRedaction = new PageAreaRedaction(regex, optionsText);
            var redactions = new Redaction[] { textRedaction };

            // Currently, custom redaction is supported only for PDFs
            using (Redactor redactor = new Redactor("sample.pdf"))
            {
                RedactorChangeLog result = redactor.Apply(redactions);
                if (result.Status != RedactionStatus.Failed)
                {
                    redactor.Save(new Options.SaveOptions(false, "Custom_Redaction_Result"));
                    Console.WriteLine("Custom redaction performed");
                }
                else
                {
                    Console.WriteLine("Custom redaction failed");
                }
            }
 
            // Implement a custom redaction handler.
            public class TextRedactor : ICustomRedactionHandler
            {
                public CustomRedactionResult Redact(CustomRedactionContext context)
                {
                    CustomRedactionResult result = new CustomRedactionResult();

                    try
                    {
                        // Use built-in tools
                        Regex regex = new Regex(@"Lorem ipsum");
                        if (regex.IsMatch(context.Text))
                        {
                            string redactedText = regex.Replace(context.Text, "[redacted-custom]");
                            result.Apply = true;
                            result.Text = redactedText;
                        }

                        // Or implement your own solution using AI tools 
                        //.....
                    }
                    catch (System.Exception ex)
                    {
                        result.Apply = false;
                    }
                    return result;
                }
            }