GroupDocs.Redaction for .NET 26.6 is now available. This release makes it easier to open documents from streams and files with an explicit format, and introduces a new drawing API that is independent of System.Drawing to improve cross-platform compatibility.

Fixes and enhancements

  • [Enhancement] Specify file type when opening a document from a stream or file path. (REDACTIONNET-572)
  • [Enhancement] Migrate away from System.Drawing to enhance cross-platform compatibility. (REDACTIONNET-799)

What’s New?

This release focuses on two areas that simplify integration and prepare the API for broader platform support.

Specify document format with LoadOptions.FileType

When you open a document, GroupDocs.Redaction normally detects its format automatically. That works well for files with a correct extension, but it can fail for streams without a file name or when the extension does not match the actual content.

Version 26.6 adds the LoadOptions.FileType property and a LoadOptions(FileType) constructor. Set FileType to a supported constant such as FileType.DOCX or FileType.PDF, and the library opens the document using that format without running binary format detection. The default behavior is unchanged when FileType is not specified or remains FileType.Unknown.

Cross-platform drawing types in GroupDocs.Redaction.Options.Drawing

Several redaction options previously relied on System.Drawing types (Color, Point, Size, Rectangle, Font). These types are not available on all platforms and can complicate deployment on Linux and in containerized environments.

The new GroupDocs.Redaction.Options.Drawing namespace provides Color, Point, Size, Rectangle, Font, and FontStyle types for use in public API. New overloads accept these types in ReplacementOptions, RegionReplacementOptions, ImageAreaRedaction, PageAreaFilter, TextFragment, and related classes.

Existing code that uses System.Drawing continues to compile and run. The corresponding members are marked obsolete and should be migrated to the new types in future updates.

Public API changes

Added

  • LoadOptions.FileType property
  • LoadOptions(FileType fileType) constructor
  • Drawing types in GroupDocs.Redaction.Options.Drawing: Color, Point, Size, Rectangle, Font, FontStyle
  • New overloads that accept GroupDocs.Redaction.Options.Drawing types

Obsolete

  • ReplacementOptions.BoxColor — use ReplacementOptions.BoxFillColor instead
  • ReplacementOptions(System.Drawing.Color) — use ReplacementOptions(GroupDocs.Redaction.Options.Drawing.Color) instead
  • RegionReplacementOptions.FillColor — use RegionReplacementOptions.AreaFillColor instead
  • RegionReplacementOptions.Size — use RegionReplacementOptions.AreaSize instead
  • RegionReplacementOptions(System.Drawing.Color, System.Drawing.Size) — use the overload with GroupDocs.Redaction.Options.Drawing.Color and GroupDocs.Redaction.Options.Drawing.Size instead
  • RegionReplacementOptions(System.Drawing.Color, System.Drawing.Font, string) — use the overload with GroupDocs.Redaction.Options.Drawing.Color and GroupDocs.Redaction.Options.Drawing.Font instead
  • ImageAreaRedaction.TopLeft — use ImageAreaRedaction.TopLeftPosition instead
  • ImageAreaRedaction(System.Drawing.Point, RegionReplacementOptions) — use the overload with GroupDocs.Redaction.Options.Drawing.Point instead
  • PageAreaFilter.Rectangle — use PageAreaFilter.AreaRectangle instead
  • PageAreaFilter(System.Drawing.Point, System.Drawing.Size) — use the overload with GroupDocs.Redaction.Options.Drawing.Point and GroupDocs.Redaction.Options.Drawing.Size instead
  • TextFragment.Rectangle — use TextFragment.BoundingRectangle instead
  • TextFragment(string, System.Drawing.Rectangle) — use TextFragment(string, GroupDocs.Redaction.Options.Drawing.Rectangle) instead
  • IImageFormatInstance.EditArea(System.Drawing.Point, RegionReplacementOptions) — use the overload with GroupDocs.Redaction.Options.Drawing.Point instead

Code examples

Open a document with an explicit file type

using System.IO;
using GroupDocs.Redaction.Options;
using GroupDocs.Redaction.Redactions;

using (Stream stream = File.OpenRead("sample.docx"))
{
    using (Redactor redactor = new Redactor(stream, new LoadOptions(FileType.DOCX)))
    {
        redactor.Apply(new DeleteAnnotationRedaction());
        redactor.Save();
    }
}

using (Redactor redactor = new Redactor("sample.pdf", new LoadOptions(FileType.PDF)))
{
    redactor.Apply(new ExactPhraseRedaction("Test", new ReplacementOptions("[redacted]")));
    redactor.Save();
}

Use GroupDocs.Redaction.Options.Drawing instead of System.Drawing

using GroupDocs.Redaction.Options.Drawing;
using GroupDocs.Redaction.Redactions;

// Previously: new ReplacementOptions(System.Drawing.Color.Red)
using (Redactor redactor = new Redactor("sample.docx"))
{
    redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(Color.Red)));
    redactor.Save();
}

// Previously: new ImageAreaRedaction(new System.Drawing.Point(516, 311),
//     new RegionReplacementOptions(System.Drawing.Color.Blue, new System.Drawing.Size(170, 35)))
using (Redactor redactor = new Redactor("sample.jpg"))
{
    redactor.Apply(new ImageAreaRedaction(new Point(516, 311),
        new RegionReplacementOptions(Color.Blue, new Size(170, 35))));
    redactor.Save();
}

How to get the update

Learn more