在 JavaScript 中檢索與更新投影片檢視屬性
簡介
在 PowerPoint 的普通檢視模式中,投影片位於側邊面板(顯示縮圖或大綱)與下方的備註面板之間。Aspose.Slides for Node.js via Java 透過 Presentation.getViewProperties 公開投影片儲存的編輯偏好設定。這些設定包括面板佈局、縮放等級、格線間距以及註解的可見性。
關於 NormalViewProperties
使用 getNormalViewProperties 取得 NormalViewProperties 類別。setShowOutlineIcons 控制是否在大綱中於投影片標題旁顯示圖示。setSnapVerticalSplitter 允許使用者縮小側邊面板時,使其自動貼齊至最小化狀態。setPreferSingleView 表示在全螢幕視窗中偏好僅顯示單一面板。
setVerticalBarState 控制側邊面板與投影片之間的分隔條。setHorizontalBarState 控制備註面板上方的分隔條。兩者皆接受 SplitterBarStateType 的 Minimized、Maximized 或 Restored 值。
關於 還原 NormalViewProperties
當分隔條被還原時,getRestoredLeft 提供側邊面板的儲存大小,而 getRestoredTop 提供上方投影片區域的儲存大小。兩者皆公開 NormalViewRestoredProperties。其 setDimensionSize 方法接受 0 到 100 之間的百分比,而 setAutoAdjust 控制編輯器在視窗大小變更時是否自動調整尺寸。
此範例會更新現有的投影片。它還原水平分隔條,將 getRestoredTop 回傳的大小設定為 80% 並啟用自動調整,並將垂直分隔條最大化。它亦呼叫 setShowOutlineIcons 以在大綱檢視中顯示圖示。
const slides = require("aspose.slides.via.java");
const presentation = new slides.Presentation("input.pptx");
try {
const normalView = presentation.getViewProperties().getNormalViewProperties();
normalView.setHorizontalBarState(slides.SplitterBarStateType.Restored);
normalView.setVerticalBarState(slides.SplitterBarStateType.Maximized);
normalView.getRestoredTop().setAutoAdjust(true);
normalView.getRestoredTop().setDimensionSize(80);
normalView.setShowOutlineIcons(true);
presentation.save("presentation_normal_view_state.pptx", slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
設定預設縮放值
getSlideViewProperties 與 getNotesViewProperties 為編輯器儲存獨立的縮放設定。這些設定不會影響投影片尺寸、投影片放映播放或影像匯出的解析度。
此範例開啟現有的投影片,並呼叫 setVariableScale 以將投影片符合編輯視窗。對於備註頁面,它停用自動縮放,並呼叫 setScale 設定固定的 80% 縮放。
const slides = require("aspose.slides.via.java");
const presentation = new slides.Presentation("input.pptx");
try {
const viewProperties = presentation.getViewProperties();
viewProperties.getSlideViewProperties().setVariableScale(true);
viewProperties.getNotesViewProperties().setVariableScale(false);
viewProperties.getNotesViewProperties().setScale(80);
presentation.save("zoom.pptx", slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
設定格線間距
setGridSpacing 設定整個投影片中編輯格線之間的距離。它接受以點為單位的正值,1 英吋等於 72 點。此範例列印現有投影片的目前間距,並將間隔設定為 18 點,以儲存四分之一英吋的格線。
const slides = require("aspose.slides.via.java");
const presentation = new slides.Presentation("input.pptx");
try {
const viewProperties = presentation.getViewProperties();
console.log("Current grid spacing: " + viewProperties.getGridSpacing() + " points");
viewProperties.setGridSpacing(18);
presentation.save("grid-spacing.pptx", slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
格線以固定間隔重複。繪圖參考線 標示個別的水平或垂直位置。兩者皆為編輯輔助工具,僅在顯示該功能的編輯器中出現。投影片放映以及匯出為 PDF、影像或 SVG 時不會包含它們。
開啟投影片時顯示或隱藏註解
setShowComments 儲存相容編輯器在開啟投影片時會使用的偏好設定。對於含有註解的現有投影片,此範例會列印目前設定,並儲存一個隱藏註解的副本。它亦呼叫 setLastView 並傳入 ViewType.SlideView,使副本以投影片檢視方式開啟。
const java = require("java");
const slides = require("aspose.slides.via.java");
const presentation = new slides.Presentation("input.pptx");
try {
const viewProperties = presentation.getViewProperties();
console.log("Current comment visibility: " + viewProperties.getShowComments());
const hideComments = java.newByte(slides.NullableBool.False);
viewProperties.setShowComments(hideComments);
viewProperties.setLastView(slides.ViewType.SlideView);
presentation.save("comments-hidden.pptx", slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
隱藏註解會保留其文字、作者、位置、回覆與狀態。若要變更註解本身,請參閱 投影片註解。匯出設定會決定註解是否出現在 PDF、HTML、影像、備註或講義中。
常見問題
為什麼重新開啟投影片時格線會被隱藏?
投影片會儲存格線間隔。若要看到格線,請在編輯器中啟用格線可見性。
清除繪圖參考線會改變格線間距嗎?
不會。新增、移動或清除參考線都不會改變格線間隔。
投影片的不同章節可以有不同的檢視設定嗎?
不會。Presentation.getViewProperties 會套用於整個投影片。
我可以為不同使用者儲存不同的檢視設定嗎?
檔案僅儲存一套檢視屬性供所有使用者使用。編輯器可能會同時套用使用者的本機偏好設定。
我可以在範本中儲存檢視設定嗎?
可以。從該範本建立的投影片會繼承其已儲存的檢視設定。