我們很高興宣布 GroupDocs.Viewer for Python 26.9 已於 2026 年 9 月 正式發佈。此版本將底層的 GroupDocs.Viewer 引擎從 26.4 升級至 26.8,新增在 Linux 與 macOS 上渲染 Microsoft Project 檔案的支援,為 Word 文件加入頁碼與解析度控制,移除非 Windows 平台對 libgdiplus 的依賴,並恢復對 Python 3.5–3.7 的相容性。嵌入的 .NET 執行時升級至 10.0.12,Python API 現已包含完整的 docstring 與程式碼範例。

本次發行的新功能

  • [Feature] 新增 WordProcessingOptions.page_number_location 與 WordsPageNumberLocation 列舉,以在渲染的 Word 文件上加蓋頁碼 (VIEWERPYTHON-153)
  • [Feature] 新增 WordProcessingOptions.horizontal_resolution / vertical_resolution,可設定 Word 文件輸出 PNG 與 JPEG 的 DPI (VIEWERPYTHON-154)
  • [Feature] 新增在 Linux 與 macOS 上渲染 Microsoft Project 檔案 (MPP、MPT、MPX) 的支援 (VIEWERPYTHON-155)
  • [Enhancement] 將 GroupDocs.Viewer 引擎從 26.4 更新至 26.8 (VIEWERPYTHON-156)
  • [Enhancement] 將嵌入的 .NET 執行時從 10.0.0 更新至 10.0.12 (VIEWERPYTHON-157)
  • [Enhancement] 移除 Linux 與 macOS 上的 libgdiplus / mono-libgdiplus 需求 (VIEWERPYTHON-158)
  • [Enhancement] 在每個平台上提供相同的 Python API——Linux 與 macOS 套件現在也支援 ProjectManagementOptions 以及 Project、Photoshop、Illustrator 與 OneNote 的 FileType 成員 (VIEWERPYTHON-159)
  • [Enhancement] 為 Python API 新增包含說明、參數與程式碼範例的 docstring (VIEWERPYTHON-160)
  • [Enhancement] 在 API 參考中加入開發者指南章節 (VIEWERPYTHON-161)
  • [Fix] 修正在 Python 3.5 – 3.7 上無法使用套件的問題 (VIEWERPYTHON-162)
  • [Fix] 修正 pip 在無法執行的 Linux 與 macOS 版本上安裝套件的問題 (VIEWERPYTHON-163)

公共 API 變更

未移除或重新命名任何項目。

新類型

Type Module Description
WordsPageNumberLocation groupdocs.viewer.options 在渲染的 Word 文件上加蓋頁碼的位置:NOT_APPLY(預設)、TOP_LEFT、TOP_CENTER、TOP_RIGHT、BOTTOM_LEFT、BOTTOM_CENTER、BOTTOM_RIGHT

現有類別的新成員

Class Member Description
WordProcessingOptions page_number_location 渲染時套用的頁碼設定(WordsPageNumberLocation)
WordProcessingOptions horizontal_resolution PNG / JPEG 輸出的水平 DPI,範圍 72 – 600(預設 96)
WordProcessingOptions vertical_resolution PNG / JPEG 輸出的垂直 DPI,範圍 72 – 600(預設 96)

Linux 與 macOS 新增項目

ProjectManagementOptions、BaseViewOptions.project_management_options 以及 FileType.MPP、MPT、MPX、PSD、PSB、AI、ONE 先前僅在 Windows 上可用,現在已同步至 Linux 與 macOS 套件——請參閱 每个平台统一的 Python API。

新功能

Linux 與 macOS 上的 Microsoft Project 檔案

過去僅能在 Windows 上渲染 MPP、MPT 與 MPX 檔案;在 Linux 與 macOS 上會出現 Failed to detect file type 錯誤。26.8 引擎在所有平台上皆能渲染,使用方式與 Windows 完全相同:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions, TimeUnit

with Viewer("project.mpp") as viewer:
    options = HtmlViewOptions.for_embedded_resources("page_{0}.html")
    options.project_management_options.time_unit = TimeUnit.DAYS
    viewer.view(options)

在 Linux 上,請先安裝 Microsoft 核心字型(ttf-mscorefonts-installer),否則會因找不到回退字型 Generic Sans Serif 而導致 Project 渲染失敗,且類似 Liberation 的相容字型無法滿足此需求。

已渲染 Word 文件的頁碼

WordProcessingOptions.page_number_location 會在渲染過程中於 Word 文件上加蓋頁碼,即使原文件本身沒有頁碼。從新加入的 WordsPageNumberLocation 列舉中選擇六個位置之一;預設 NOT_APPLY 代表不加頁碼,保持文件原樣。

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, WordsPageNumberLocation

with Viewer("document.docx") as viewer:
    options = PdfViewOptions("output.pdf")
    options.word_processing_options.page_number_location = WordsPageNumberLocation.BOTTOM_CENTER
    viewer.view(options)

Word 文件的 PNG 與 JPEG 輸出解析度

WordProcessingOptions.horizontal_resolution 與 vertical_resolution 可設定從 Word 文件渲染出的影像 DPI。預設為 96 DPI,超出 72 – 600 DPI 範圍的值會自動限制在此區間內。

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

with Viewer("document.docx") as viewer:
    options = PngViewOptions("page_{0}.png")
    options.word_processing_options.horizontal_resolution = 300
    options.word_processing_options.vertical_resolution = 300
    viewer.view(options)

不再需要 libgdiplus

Linux 與 macOS 套件改以 SkiaSharp 與 Aspose.Drawing 進行渲染,這兩者已內建於 wheel 中,從未呼叫 libgdiplus。因此在容器或映像檔中可直接移除 libgdiplus / mono-libgdiplus 以及相關的圖形相依套件。

每个平台统一的 Python API

先前的 Linux 與 macOS 套件僅提供較小的 API,與 Windows 版不一致。26.9 版在所有平台上提供相同的 API,讓程式碼可直接跨平台使用。Linux 與 macOS 現已支援 ProjectManagementOptions 以及 FileType.MPP、MPT、MPX 成員。

同時也加入了 FileType.PSD、PSB、AI 與 ONE 成員。這些格式仍僅限 Windows,若在 Linux 或 macOS 上存取會拋出 GroupDocsViewerException: Member 'GroupDocs.Viewer.FileType.PSD' not found.。若需在執行時判斷格式是否受支援,可使用:

from groupdocs.viewer import FileType

supported = {file_type.extension for file_type in FileType.get_supported_file_types()}
print(".psd" in supported)   # Windows 為 True,Linux/macOS 為 False
print(".mpp" in supported)   # 所有平台皆為 True

程式碼範例

在 Linux 或 macOS 上以每日為單位渲染 Microsoft Project 檔案:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions, TimeUnit

with Viewer("project.mpp") as viewer:
    options = HtmlViewOptions.for_embedded_resources("page_{0}.html")
    options.project_management_options.time_unit = TimeUnit.DAYS
    viewer.view(options)

為 Word 文件加頁碼並渲染為 PDF:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, WordsPageNumberLocation

with Viewer("document.docx") as viewer:
    options = PdfViewOptions("output.pdf")
    options.word_processing_options.page_number_location = WordsPageNumberLocation.BOTTOM_CENTER
    viewer.view(options)

如何取得更新

PyPI

透過 PyPI 升級至最新套件:

pip install groupdocs-viewer-net==26.9.0

直接下載

前往 GroupDocs.Viewer for Python via .NET 26.9 頁面下載所有平台的 wheel 檔案。

資源