GroupDocs.Redaction for Python via .NET 26.11 Release Notes

This release upgrades the GroupDocs.Redaction engine from 26.5 to 26.10, and the embedded .NET runtime from 10.0.0 to 10.0.15. The engine now draws with Aspose.Drawing and SkiaSharp instead of System.Drawing, so rasterized PDF output and image-area redaction work on Linux and macOS as they do on Windows. New are page previews, a Python logger, a Python OCR connector, the OOXML compliance level of a saved Word document, opening a document as a given file type, and License().is_licensed. In evaluation mode the engine opens up to 25 documents per process and no longer limits redactions or replacements; long documents are still cut short. The package is the first built on groupdocs-shared-net, which pip installs with it.

Breaking change: colors and geometry come from groupdocs.redaction.options.drawing, as in the .NET API: a Color, Point or Size from groupdocs.pydrawing raises TypeError, and from groupdocs.redaction import Color raises ImportError. A redaction callback’s description.redaction_type and description.action_type are enums (RedactionType.TEXT), no longer names. The wheel platform tags changed (Linux manylinux1 → manylinux_2_27, macOS Intel 10.14 → 12.0, macOS Apple Silicon 11.0 → 12.0), so pip 20.3 or newer is required. See API Changes for the full list.

Full List of Changes in This Release

KeyCategorySummary
REDACTIONPYTHONNET‑23FeatureAdd support for page previews to files and io.BytesIO (PreviewOptions, generate_preview())
REDACTIONPYTHONNET‑24FeatureAdd support for a Python logger (ILogger)
REDACTIONPYTHONNET‑25FeatureAdd support for a Python OCR connector (IOcrConnector) to redact text in images
REDACTIONPYTHONNET‑26FeatureAdd support for setting the OOXML compliance level of a saved Word document (ooxml_compliance)
REDACTIONPYTHONNET‑27FeatureAdd support for opening a document as a given file type (LoadOptions.file_type)
REDACTIONPYTHONNET‑28FeatureAdd support for checking whether a license is applied (License.is_licensed)
REDACTIONPYTHONNET‑29EnhancementUpdate GroupDocs.Redaction to 26.10 and the embedded runtime to .NET 10.0.15
REDACTIONPYTHONNET‑30EnhancementReplace groupdocs.pydrawing types with groupdocs.redaction.options.drawing (Color, Point, Size, Rectangle, Font, FontStyle)
REDACTIONPYTHONNET‑31EnhancementReturn RedactionType and RedactionActionType enums from a redaction callback’s description
REDACTIONPYTHONNET‑32EnhancementRaise AttributeError when an unknown attribute is assigned to an API object
REDACTIONPYTHONNET‑33EnhancementRaise LicenseError for a license that cannot be applied, and export it and GroupDocsRedactionException from groupdocs.redaction
REDACTIONPYTHONNET‑34EnhancementInstall groupdocs.pydrawing and groupdocs.pycore from the shared groupdocs-shared-net package
REDACTIONPYTHONNET‑12FixFix CVE findings in 26.6.0: .NET runtime 10.0.0 → 10.0.15 (+2 more)
REDACTIONPYTHONNET‑35FixRasterized PDF output and image-area redaction raise PlatformNotSupportedException on Linux and macOS
REDACTIONPYTHONNET‑36FixA redaction callback fails with JSONDecodeError on text that contains a tab
REDACTIONPYTHONNET‑37FixRedactorSettings raises TypeError for a redaction callback passed as its only argument
REDACTIONPYTHONNET‑38FixWheels install on Linux and macOS versions the embedded .NET runtime cannot run on

Major Features

Page previews

Redactor.generate_preview() renders document pages to images. PreviewOptions takes a function that returns a stream for each page, an open binary file or an io.BytesIO, and optionally a second function that releases each page’s stream. Set width, height and page_numbers. 26.6.0 refused a Python function there with TypeError.

import io
from groupdocs.redaction import Redactor
from groupdocs.redaction.options import PreviewOptions, PreviewFormats

pages = {}

def create_page_stream(page_number):
    pages[page_number] = io.BytesIO()
    return pages[page_number]

with Redactor("document.pdf") as redactor:
    options = PreviewOptions(create_page_stream)
    options.width, options.height = 300, 400
    options.page_numbers = [1]
    options.preview_format = PreviewFormats.PNG
    redactor.generate_preview(options)

print(len(pages[1].getvalue()), "bytes of PNG")

Python logger

RedactorSettings(logger=...) takes an object with error(message), warning(message) and trace(message), and the engine reports through it. 26.6.0 refused a Python logger with TypeError.

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import LoadOptions, RedactorSettings

class PrintLogger:
    def error(self, message):
        print("ERROR", message)

    def warning(self, message):
        print("WARNING", message)

    def trace(self, message):
        print("TRACE", message)

with Redactor("document.docx", LoadOptions(), RedactorSettings(logger=PrintLogger())) as redactor:
    print(redactor.get_document_info().page_count)

Python OCR connector

GroupDocs.Redaction ships no OCR engine. RedactorSettings(ocr_connector=...) takes an object with recognize(image_stream) that returns what your OCR engine found: a RecognizedImage of TextLines of TextFragments, each with its text and rectangle. The engine then finds the phrases in the image and paints over them. Report each line of text as one TextFragment. 26.6.0 refused a Python connector with TypeError.

from groupdocs.redaction import Redactor
from groupdocs.redaction.integration.ocr import RecognizedImage, TextFragment, TextLine
from groupdocs.redaction.options import LoadOptions, RedactorSettings
from groupdocs.redaction.options.drawing import Color, Rectangle
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions

class MyOcr:
    def recognize(self, image_stream):
        image_bytes = image_stream.read()           # pass these to your OCR engine
        line = TextFragment("John Doe", Rectangle(40, 40, 230, 40))   # one fragment per line
        return RecognizedImage([TextLine([line])])

with Redactor("scan.png", LoadOptions(), RedactorSettings(ocr_connector=MyOcr())) as redactor:
    print(redactor.apply(ExactPhraseRedaction("John Doe", ReplacementOptions(Color.black))).status.name)

OOXML compliance level of a saved Word document

SaveOptions.wordprocessing_save_options.ooxml_compliance sets the OOXML compliance level of a saved Word document: WordProcessingComplianceLevel.ECMA, TRANSITIONAL or STRICT. Unset, the document keeps the level it had. 26.6.0 did not have it.

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions, WordProcessingComplianceLevel
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions

with Redactor("document.docx") as redactor:
    redactor.apply(ExactPhraseRedaction("John Doe", ReplacementOptions("[personal]")))
    options = SaveOptions(rasterize_to_pdf=False, add_suffix=True)
    options.wordprocessing_save_options.ooxml_compliance = WordProcessingComplianceLevel.STRICT
    print(redactor.save(options))   # document_Redacted.docx, ISO/IEC 29500 Strict

Open a document as a given file type

LoadOptions(file_type) opens a stream, or a file whose name does not say its format, as the given FileType. 26.6.0 did not have it.

from groupdocs.redaction import Redactor, FileType
from groupdocs.redaction.options import LoadOptions
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions

with open("document.docx", "rb") as stream:
    with Redactor(stream, LoadOptions(FileType.DOCX)) as redactor:
        status = redactor.apply(ExactPhraseRedaction("John Doe", ReplacementOptions("[personal]"))).status
        print(status.name)

Check whether a license is applied

License().is_licensed is True once a license is applied, with License().set_license() or from the GROUPDOCS_LIC_PATH environment variable.

from groupdocs.redaction import License

print(License().is_licensed)

API Changes

Upgraders need to import colors and geometry from groupdocs.redaction.options.drawing, and to compare a redaction callback’s redaction_type and action_type with enum members. Everything else is additive.

New classes and members

  • groupdocs.redaction: CancellationToken, CancellationTokenSource, OperationCanceledError, LicenseError, LicenseWarning, GroupDocsRedactionException.
  • groupdocs.redaction.options: WordProcessingComplianceLevel, WordprocessingSaveOptions.
  • groupdocs.redaction.options.drawing: Color, Font, FontStyle, Point, Rectangle, Size.
  • FileType: DJVU, LOG, OTP, POTM, POTX, PPS, PPSM, PPSX, PPTM, TAB, WEBP, XLT, XLTM, XLTX.
  • License: is_licensed.
  • LoadOptions: file_type.
  • SaveOptions: wordprocessing_save_options.

groupdocs.redaction.options.drawing is a new module. GroupDocsRedactionException is still exported by groupdocs.redaction.exceptions too.

Removed

The groupdocs.pydrawing color that 26.6 re-exported; import Color from groupdocs.redaction.options.drawing instead:

  • groupdocs.redaction.Color
  • groupdocs.redaction.redactions.Color

Changed

  • Every member that takes or returns a color, point, size or rectangle uses the groupdocs.redaction.options.drawing types. A groupdocs.pydrawing value raises TypeError (no overload matched).
  • RedactionDescription.redaction_type and action_type, which a redaction callback reads, are RedactionType and RedactionActionType members.
  • The engine’s obsolete aliases are present too: ReplacementOptions.box_fill_color, RegionReplacementOptions.area_fill_color and area_size, ImageAreaRedaction.top_left_position, PageAreaFilter.area_rectangle and TextFragment.bounding_rectangle. Use box_color, fill_color, size, top_left and rectangle.

Fixed

  • Fix CVE findings in 26.6.0: .NET runtime 10.0.0 → 10.0.15 (+2 more) (REDACTIONPYTHONNET‑12). The 26.6.0 wheels shipped the .NET 10.0.0 runtime, System.Formats.Asn1 7.0.0 and libpng 1.6.44 in libSkiaSharp, which a CVE scan reported as high severity. 26.11.0 ships the .NET 10.0.15 runtime with its own System.Formats.Asn1, and SkiaSharp 4.152.1, whose native libraries link libpng 1.6.58.
  • Rasterized PDF output and image-area redaction raise PlatformNotSupportedException on Linux and macOS (REDACTIONPYTHONNET‑35). 26.6.0 linked an engine build that draws with System.Drawing.Common, which has no Linux or macOS implementation, so the default save(), which rasterizes to PDF, and ImageAreaRedaction raised PlatformNotSupportedException there. The engine now draws with Aspose.Drawing and SkiaSharp on every platform, and needs no libgdiplus.
  • A redaction callback fails with JSONDecodeError on text that contains a tab (REDACTIONPYTHONNET‑36). The callback’s arguments were built as JSON by hand without escaping control characters, so a match that contained a tab failed with JSONDecodeError: Invalid control character. The callback now receives the engine’s RedactionDescription with the text intact, and the redaction reports APPLIED.
  • RedactorSettings raises TypeError for a redaction callback passed as its only argument (REDACTIONPYTHONNET‑37). The function was matched to the logger overload and failed with TypeError: _marshal_callback_or_handle: cannot wrap function as GroupDocs.Redaction.Options.ILogger. RedactorSettings(callback) now takes a function, or an object with accept_redaction, as the redaction callback.
  • Wheels install on Linux and macOS versions the embedded .NET runtime cannot run on (REDACTIONPYTHONNET‑38). The 26.6.0 wheels were tagged manylinux1, macosx_10_14 and macosx_11_0, so pip installed them on systems where the embedded .NET 10 runtime cannot start. The 26.11.0 wheels are tagged manylinux_2_27 and macosx_12_0, the oldest systems the runtime’s binaries support, and need pip 20.3 or newer.

Known Issues

  • Saving a PDF/A (RasterizationOptions.compliance = PdfComplianceLevel.PDF_A1A) to a file opened with "wb" raises NotImplementedError: Stream does not support reading, because the engine reads its output back. Open the file with "w+b", or save to an io.BytesIO.

Requirements

  • Python 3.5 – 3.14 (python_requires = ">=3.5,<3.15") and pip 20.3 or newer
  • Linux x64 with glibc 2.27 or newer; macOS 12 or newer, Intel or Apple Silicon. On an Intel Mac, a Python built against a pre-11 macOS SDK reports the system as macOS 10.16 — use pip 24.1 or newer there, or SYSTEM_VERSION_COMPAT=0 pip install groupdocs-redaction-net
  • groupdocs-shared-net 26.11.0 or newer, which pip installs with the package
  • Windows: no additional packages
  • Linux: ICU and fontconfig — apt-get install libicu-dev libfontconfig1 (fontconfig serves presentations: without it no PowerPoint or OpenDocument presentation opens). Without libfontconfig1, opening a PPTX, PPT, PPS, PPSX, PPSM, PPTM, POTX, POTM, ODP or OTP file fails with DllNotFoundException for libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so; every other format needs only ICU. Install the fonts your documents use for faithful rasterized output. libgdiplus and the Microsoft core fonts are not needed.
  • macOS (Intel and Apple Silicon): no additional packages
  • The .NET 10.0.15 runtime is embedded in the wheel; no separate install is needed

Wheel Distribution

The wheels are on PyPI, where pip 20.3 or newer picks the one for your platform and installs groupdocs-shared-net with it, and on releases.groupdocs.com for a machine without PyPI access. There, install the downloaded wheel together with groupdocs_shared_net-26.11.0-py3-none-any.whl from PyPI: put both in one folder and run pip install --no-index --find-links <folder> groupdocs-redaction-net.

PlatformDownloadWheel
Windows x64Windowsgroupdocs_redaction_net-26.11.0-py3-none-win_amd64.whl
Linux x64Linuxgroupdocs_redaction_net-26.11.0-py3-none-manylinux_2_27_x86_64.whl
macOS IntelmacOS Intelgroupdocs_redaction_net-26.11.0-py3-none-macosx_12_0_x86_64.whl
macOS Apple SiliconmacOS Apple Silicongroupdocs_redaction_net-26.11.0-py3-none-macosx_12_0_arm64.whl
pip install groupdocs-redaction-net==26.11.0

Additional Resources

Feedback

Questions and issues are welcome on the GroupDocs.Redaction forum.