我们很高兴宣布 GroupDocs.Watermark for Python v26.10 已于 2026年10月 发布。此版本将底层 .NET 引擎从 26.6 升级至 26.9,嵌入的 .NET 运行时从 10.0.0 升级至 10.0.12。它引入了对自定义日志记录器的支持,强制更严格的属性赋值,并修复了预览回调和页面流处理的关键问题。此外,兼容性扩展至 Python 3.5–3.14,并通过严格的 wheel 标签明确了平台支持。

本次发布的新功能

  • [功能] 接受 Python 对象或函数作为 WatermarkerSettings.logger (WATERMARKPYTHON-65)
  • [增强] 将 GroupDocs.Watermark 引擎从 26.6 更新至 26.9 (WATERMARKPYTHON-66)
  • [增强] 将嵌入的 .NET 运行时从 10.0.0 更新至 10.0.12 (WATERMARKPYTHON-67)
  • [增强] 当代码为类分配不存在的属性时抛出 AttributeError (WATERMARKPYTHON-68)
  • [修复] 在 Python 3.5 – 3.7 上无法使用该包 (WATERMARKPYTHON-69)
  • [修复] pip 在无法运行的 Linux 和 macOS 版本上安装该包 (WATERMARKPYTHON-70)
  • [修复] 预览发布回调收到 None 而不是页面流 (WATERMARKPYTHON-71)
  • [修复] 写入 io.BytesIO 的页面预览为空 (WATERMARKPYTHON-72)
  • [修复] 通过发布回调写入的电子表格页面预览被截断 (WATERMARKPYTHON-73)

公共 API 更改

升级需要使用新的 wheel(pip ≥ 20.3)并处理拼写错误属性导致的新的 AttributeError;其他 API 签名保持不变。

新类和成员

  • Color:一个构造函数;之前没有。
  • get() 在 4 个索引类上 — ReadOnlyListBase、SpreadsheetHeaderFooterCollection、SpreadsheetHeaderFooterSectionCollection、WordProcessingHeaderFooterCollection — 作为 x[key] 的替代;它们的 item 属性已被移除。

新功能

WatermarkerSettings 的自定义日志记录器

WatermarkerSettings.logger 现在接受 Python 对象或普通函数。在 26.6 中为其分配任何值会抛出

TypeError: _marshal_callback_or_handle: cannot wrap ... as GroupDocs.Watermark.Options.ILogger

日志记录器可以是实现了 trace(message)、warning(message) 和 error(message, exception) 方法的对象,或是可调用的 fn(level, message, exception)。引擎在打开文件时记录 trace,在无法加载文件时记录 error(包含 .NET 异常文本);日志记录器内部的失败会被忽略。

from groupdocs.watermark import Watermarker, WatermarkerSettings

class PrintLogger:
    def trace(self, message):
        print("trace:", message)

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

    def error(self, message, exception):
        print("error:", message, exception)

settings = WatermarkerSettings()
settings.logger = PrintLogger()  # object with the required methods
# or: settings.logger = lambda level, msg, exc: print(level, msg, exc)

with Watermarker("document.pdf", settings) as watermarker:
    print(watermarker.get_document_info().page_count)

严格的属性赋值

在 watermark 包装器上为拼写错误或 .NET 风格的属性赋值现在会抛出 AttributeError,而不是悄悄创建仅 Python 的属性。这可防止代码误以为已更改文档却实际上未更改。

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font

with Watermarker("document.pdf") as wm:
    watermark = TextWatermark("CONFIDENTIAL", Font("Arial", 36))
    # The following line raises an error because the property name is wrong
    watermark.opacity_level = 0.5

抛出的错误为:

AttributeError: 'TextWatermark' object has no attribute 'opacity_level'; assigning it would not reach the .NET object. Did you mean: 'opacity'?

现有的正确属性赋值仍保持不变。

代码示例

请参阅上文的 WatermarkerSettings 的自定义日志记录器 和 严格的属性赋值 部分。

如何获取更新

PyPI

直接下载

从 GroupDocs.Watermark for Python via .NET 26.10 页面下载 Windows、Linux 和 macOS 的 wheel。

资源