我们很高兴宣布 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] 修复在 Linux 与 macOS 上 pip 安装后无法运行的情况 (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 相同的 ProjectManagementOptions:
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):若缺少这些字体,项目渲染会因 Cannot find fallback font 'Generic Sans Serif' 而失败,而类似 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 及其图形依赖的 Linux 容器中运行。请从镜像和部署脚本中移除 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.。如需在运行时判断某格式是否可渲染,请使用 FileType.get_supported_file_types(),该方法仅返回当前引擎支持的类型:
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 文件。