在 Python via Java 中檢索與更新簡報檢視屬性

簡介

一般檢視由三個內容區域組成:投影片本身、側邊內容區域以及底部內容區域。一般檢視屬性描述這些內容區域的位置。此資訊讓應用程式能將檢視狀態儲存至檔案,以便重新開啟時,檢視與上次儲存簡報時的狀態相同。

已新增 ViewProperties.getNormalViewProperties 方法,以提供存取簡報的一般檢視屬性。

已新增 NormalViewPropertiesNormalViewRestoredProperties 類別以及 SplitterBarStateType 列舉。

關於 NormalViewProperties

代表一般檢視屬性。

方法 getShowOutlineIconssetShowOutlineIcons 指定在一般檢視模式的任何內容區域顯示大綱內容時,應否顯示圖示。

方法 getSnapVerticalSplittersetSnapVerticalSplitter 指定當側邊區域足夠小時,垂直分割線是否應自動收合。

方法 getPreferSingleViewsetPreferSingleView 指定使用者是否偏好以全視窗單一內容區域取代具有三個內容區域的標準一般檢視。啟用後,應用程式可能會選擇在整個視窗中顯示其中一個內容區域。

方法 getVerticalBarStategetHorizontalBarState 指定水平或垂直分割條應顯示的狀態。水平分割條將投影片與投影片下方的內容區域分開;垂直分割條將投影片與側邊內容區域分開。可能的值有: SplitterBarStateType.MinimizedSplitterBarStateType.MaximizedSplitterBarStateType.Restored

方法 getRestoredLeftgetRestoredTop 指定在將 SplitterBarStateType.Restored 值套用至 getVerticalBarStategetHorizontalBarState 時,一般檢視的側邊或上方投影片區域的大小。

關於還原 NormalViewProperties

指定當區域為可變還原大小(既非最小化也非最大化)時,一般檢視的投影片區域(若為 getRestoredTop 的子項則為寬度,若為 getRestoredLeft 的子項則為高度)的尺寸。

方法 getDimensionSize 指定投影片區域的大小(同上)。

方法 getAutoAdjust 指定在調整包含該檢視之視窗大小時,側邊內容區域是否應自動補償新的尺寸。

以下範例示範如何存取簡報的 ViewProperties.getNormalViewProperties

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Presentation, SaveFormat, SplitterBarStateType

presentation = Presentation()
try:
    normal_view_properties = presentation.getViewProperties().getNormalViewProperties()
    normal_view_properties.setHorizontalBarState(SplitterBarStateType.Restored)
    normal_view_properties.setVerticalBarState(SplitterBarStateType.Maximized)

    # 還原簡報的檢視屬性。
    normal_view_properties.getRestoredTop().setAutoAdjust(True)
    normal_view_properties.getRestoredTop().setDimensionSize(80)
    normal_view_properties.setShowOutlineIcons(True)

    presentation.save("presentation_normal_view_state.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

設定預設縮放值

設定檢視屬性,請依照以下步驟:

  1. 建立 Presentation 類別的實例。
  2. 設定 PresentationView Properties
  3. 將簡報寫入 PPTX 檔案。

在下方範例中,我們同時為投影片檢視與備註檢視設定縮放值。

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Presentation, SaveFormat

presentation = Presentation()
try:
    # 設定簡報的檢視屬性。
    presentation.getViewProperties().getSlideViewProperties().setScale(100)  # 投影片檢視的縮放百分比。
    presentation.getViewProperties().getNotesViewProperties().setScale(100)  # 備註檢視的縮放百分比。

    presentation.save("Zoom_out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

常見問題

我能為簡報的不同章節設定不同的檢視設定嗎?

View settings 於簡報層級定義(Normal View/Slide View),不是依章節切分。因此單一組參數在檔案開啟時套用於整個文件。

我能為不同使用者預先定義不同的檢視狀態嗎?

不能。設定儲存在檔案中,且為共用。檢視程式可能會遵守使用者偏好,但檔案本身僅包含一組檢視屬性。

我可以建立包含預先定義 View Properties 的範本,使新簡報以相同方式開啟嗎?

可以。因為 view properties 儲存在簡報層級,您可以將其嵌入範本,然後以該範本建立新文件,從而取得相同的初始檢視設定。