在 Android 上檢索與更新簡報檢視屬性
簡介
普通檢視包含三個內容區域:投影片本身、側邊內容區域和底部內容區域。與不同內容區域定位相關的屬性。此資訊允許應用程式將檢視狀態儲存至檔案,使得重新開啟時檢視狀態與上次儲存簡報時相同。
已新增方法IViewProperties.getNormalViewProperties以提供對簡報普通檢視屬性的存取。
已新增 INormalViewProperties、INormalViewRestoredProperties 介面及其衍生類別,以及 SplitterBarStateType 列舉。
關於 INormalViewProperties
代表普通檢視屬性。
方法getShowOutlineIcons和setShowOutlineIcons指定當在普通檢視模式的任何內容區域顯示大綱內容時,應用程式是否應顯示圖示。
方法getSnapVerticalSplitter和setSnapVerticalSplitter指定當側邊區域足夠小時,垂直分割線是否應自動貼齊至最小化狀態。
屬性getPreferSingleView和setPreferSingleView指定使用者是否偏好在全視窗單一內容區域顯示,而不是具有三個內容區域的標準普通檢視。啟用後,應用程式可能會選擇將其中一個內容區域顯示於整個視窗。
方法getVerticalBarState和getHorizontalBarState指定水平或垂直分割條應顯示的狀態。水平分割條將投影片與投影片下方的內容區域分開,垂直分割條將投影片與側邊內容區域分開。可能的值包括:SplitterBarStateType.Minimized、SplitterBarStateType.Maximized和SplitterBarStateType.Restored。
方法getRestoredLeft和getRestoredTop指定普通檢視中上方或側邊投影片區域的大小,當對getVerticalBarState和getHorizontalBarState套用SplitterBarStateType.Restored值時。
關於還原 INormalViewProperties
指定普通檢視中投影片區域的大小(若為getRestoredTop的子項則為寬度,若為getRestoredLeft的子項則為高度),當該區域為可變的還原大小(既非最小化亦非最大化)時。
方法getDimensionSize指定投影片區域的大小(若為 restoredTop 的子項則為寬度,若為 restoredLeft 的子項則為高度)。
方法getAutoAdjust指定在調整包含檢視的視窗大小時,側邊內容區域的大小是否應自動調整以補償新尺寸。
以下範例說明如何存取簡報的ViewProperties.getNormalViewProperties 屬性。
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
pres.getViewProperties().getNormalViewProperties().setHorizontalBarState(SplitterBarStateType.Restored);
pres.getViewProperties().getNormalViewProperties().setVerticalBarState(SplitterBarStateType.Maximized);
// 復原簡報的檢視屬性
pres.getViewProperties().getNormalViewProperties().getRestoredTop().setAutoAdjust(true);
pres.getViewProperties().getNormalViewProperties().getRestoredTop().setDimensionSize(80);
pres.getViewProperties().getNormalViewProperties().setShowOutlineIcons(true);
pres.save("presentation_normal_view_state.pptx", SaveFormat.Pptx);
} finally {
pres.dispose();
}
設定預設縮放值
若要設定檢視屬性,請依照以下步驟操作:
- 建立 Presentation 類別的實例。
- 設定 Presentation 的View Properties。
- 將簡報寫入為 PPTX 檔案。
在以下示例中,我們已設定投影片檢視和備註檢視的縮放值。
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
// 設定簡報的檢視屬性
presentation.getViewProperties().getSlideViewProperties().setScale(100); // 投影片檢視的縮放值(百分比)
presentation.getViewProperties().getNotesViewProperties().setScale(100); // 備註檢視的縮放值(百分比)
presentation.save("Zoom_out.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
設定格線間距
使用 Presentation.getViewProperties 取得整個簡報的檢視設定。IViewProperties.getGridSpacing 與 IViewProperties.setGridSpacing 方法可讀取或變更基礎編輯格線的間隔。此設定套用於整個簡報,而非單一投影片。格線間距以點 (point) 為單位,72 點等於一吋。請使用正值,符合 API 文件的要求。
以下範例開啟現有的 demo.pptx,列印其目前的格線間距,設定四分之一吋的間隔,並儲存結果。
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
Presentation presentation = new Presentation("demo.pptx");
try {
float gridSpacing = presentation.getViewProperties().getGridSpacing();
System.out.println("Current grid spacing: " + gridSpacing + " points");
presentation.getViewProperties().setGridSpacing(18f);
presentation.save("grid-spacing.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
格線與drawing guides 不同。格線間距控制固定的間隔,而繪圖輔助線是個別定位的水平或垂直對齊線。新增、移動或清除繪圖輔助線不會改變格線間距。
格線與繪圖輔助線皆為編輯輔助工具。它們不會在 PDF、圖片、SVG 或投影片放映中渲染為投影片內容。即使儲存了格線間距,也無法保證編輯器會顯示格線;其可見性亦取決於檢視器或編輯器的偏好設定。
開啟簡報時顯示或隱藏註解
使用 Presentation.getViewProperties 取得整個簡報的檢視設定。使用 IViewProperties.getShowComments 與 IViewProperties.setShowComments 讀取或變更儲存的偏好,決定簡報在 PowerPoint 或其他相容編輯器開啟時是否顯示註解。
此設定僅控制儲存的檢視偏好,並不會新增、移除、編輯或解決註解。隱藏註解會保留其內容、作者、位置、回覆與狀態。請參閱 Presentation Comments 了解會變更註解本身的操作。
以下範例需要一個包含註解的現有 comments.pptx。它會列印目前的可見性設定、要求隱藏註解,並儲存一個未移除任何註解的新 PPTX。範例同時使用 IViewProperties.setLastView 搭配 ViewType.SlideView 來設定初始編輯檢視以及註解的可見性。
import com.aspose.slides.NullableBool;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import com.aspose.slides.ViewType;
Presentation presentation = new Presentation("comments.pptx");
try {
byte showComments = presentation.getViewProperties().getShowComments();
System.out.println("Current comment visibility: " + showComments);
presentation.getViewProperties().setShowComments(NullableBool.False);
presentation.getViewProperties().setLastView(ViewType.SlideView);
presentation.save("comments-hidden.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
此設定不會決定註解是否會被納入 PDF、HTML、影像、備註或講義的匯出。請另行設定相關的匯出選項。
常見問題
為何重新開啟簡報後格線不見了?
檔案會儲存格線間距,但是否顯示格線由編輯器決定。請檢查編輯器的格線可見性設定。
清除繪圖輔助線會改變格線間距嗎?
不會。繪圖輔助線與格線間距是獨立的設定。清除輔助線不會改變已儲存的格線間隔。
我能為簡報的不同節設定不同的檢視設定嗎?
檢視設定 於簡報層級定義(Normal View / Slide View),而非每個節。因此開啟文件時,整個文件僅會套用同一組參數。
我能為不同使用者預先定義不同的檢視狀態嗎?
不能。設定儲存在檔案中且為共用。檢視程式可能會遵循使用者偏好,但檔案本身僅包含一套檢視屬性。
我能製作帶有預先定義檢視屬性的範本,使新簡報以相同方式開啟嗎?
可以。由於檢視屬性 儲存在簡報層級,您可以將其嵌入範本,並以此建立新文件,使其以相同的初始檢視設定開啟。