我們很高興宣布 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 標籤得到說明。

此版本的新功能

  • [Feature] 接受 Python 物件或函式作為 WatermarkerSettings.logger (WATERMARKPYTHON-65)
  • [Enhancement] 將 GroupDocs.Watermark 引擎從 26.6 更新至 26.9 (WATERMARKPYTHON-66)
  • [Enhancement] 將嵌入的 .NET 執行時從 10.0.0 更新至 10.0.12 (WATERMARKPYTHON-67)
  • [Enhancement] 當程式碼為類別未定義的屬性指派時拋出 AttributeError (WATERMARKPYTHON-68)
  • [Fix] 無法在 Python 3.5 – 3.7 上使用此套件 (WATERMARKPYTHON-69)
  • [Fix] pip 在無法執行的 Linux 與 macOS 版本上安裝此套件 (WATERMARKPYTHON-70)
  • [Fix] 預覽發佈回呼收到 None 而非頁面串流 (WATERMARKPYTHON-71)
  • [Fix] 寫入 io.BytesIO 的頁面預覽為空 (WATERMARKPYTHON-72)
  • [Fix] 透過發佈回呼寫入的試算表頁面預覽被截斷 (WATERMARKPYTHON-73)

公開 API 變更

升級需要使用新的 wheel(pip ≥ 20.3)並處理因拼寫錯誤屬性而產生的新的 AttributeError;其他 API 簽名保持不變。

新類別與成員

  • Color:一個建構函式;之前沒有。
  • 在 4 個索引類別上使用 get() — 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。

資源