在 PHP 中管理簡報縮放
簡介
PowerPoint 縮放功能讓您在投影片放映期間在特定投影片和章節之間導覽。使用 Aspose.Slides for PHP via Java,您可以建立投影片、章節和摘要縮放,並自訂它們的預覽、邊框和過渡效果。

- 要在單一投影片上匯總整個簡報,請使用Summary Zoom。
- 僅顯示選取的投影片,請使用Slide Zoom。
- 僅顯示單一章節,請使用Section Zoom。
投影片縮放
投影片縮放可以讓您的簡報更具動態性,讓您能以任意順序自由導覽投影片,而不會中斷簡報的流程。投影片縮放非常適合章節不多的短篇簡報,但您仍可在各種簡報情境中使用它們。
投影片縮放讓您能從單一概覽投影片探索相關資訊。

對於投影片縮放物件,Aspose.Slides 提供 ZoomImageType 列舉、ZoomFrame 類別,以及 ShapeCollection 類別上的方法。
建立縮放框格
使用 ShapeCollection::addZoomFrame 在概覽投影片上放置指向個別投影片的連結。本範例建立兩個具有不同背景與標籤的目標投影片,然後將每個投影片的預覽加入第一張投影片,並將簡報另存為 PPTX。框格的位置和尺寸以點為單位指定。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$secondSlide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$thirdSlide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$secondSlide->getBackground()->setType(BackgroundType::OwnBackground);
$secondSlide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$secondSlide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$textBox = $secondSlide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 200, 500, 200);
$textBox->getTextFrame()->setText("Second Slide");
$thirdSlide->getBackground()->setType(BackgroundType::OwnBackground);
$thirdSlide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 189, 183, 107);
$thirdSlide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$textBox = $thirdSlide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 200, 500, 200);
$textBox->getTextFrame()->setText("Third Slide");
$overviewSlide->getShapes()->addZoomFrame(20, 20, 250, 200, $secondSlide);
$overviewSlide->getShapes()->addZoomFrame(200, 250, 250, 200, $thirdSlide);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
使用自訂影像建立縮放框格
將自訂影像傳遞給 ShapeCollection::addZoomFrame 以取代目標投影片的預設預覽。本範例需要本機影像,使用 Images::fromFile 讀取,並透過 ImageCollection::addImage 加入簡報。產生的框格會顯示該影像,同時仍連結至第二張投影片。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Images;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$textBox = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 200, 500, 200);
$textBox->getTextFrame()->setText("Second Slide");
$image = Images::fromFile("image.png");
try {
$previewImage = $presentation->getImages()->addImage($image);
} finally {
$image->dispose();
}
$overviewSlide->getShapes()->addZoomFrame(20, 20, 300, 200, $slide, $previewImage);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
格式化縮放框格
此範例自訂兩個投影片縮放框格。它透過 ZoomObject::setZoomImage 為第一個框格指定本機影像,並使用 Shape::getLineFormat 為第二個框格設定五點、虛線點劃的粉紅色邊框。將 false 傳遞給 ZoomObject::setShowBackground 會隱藏第二個框格的背景。自訂預覽需要本機影像;兩個框格在儲存的 PPTX 中仍保留其投影片目標。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Images;
use aspose\slides\LineDashStyle;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$secondSlide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$thirdSlide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$secondSlide->getBackground()->setType(BackgroundType::OwnBackground);
$secondSlide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$secondSlide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$textBox = $secondSlide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 200, 500, 200);
$textBox->getTextFrame()->setText("Second Slide");
$thirdSlide->getBackground()->setType(BackgroundType::OwnBackground);
$thirdSlide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 189, 183, 107);
$thirdSlide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$textBox = $thirdSlide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 200, 500, 200);
$textBox->getTextFrame()->setText("Third Slide");
$firstZoomFrame = $overviewSlide->getShapes()->addZoomFrame(20, 20, 250, 200, $secondSlide);
$secondZoomFrame = $overviewSlide->getShapes()->addZoomFrame(200, 250, 250, 200, $thirdSlide);
$image = Images::fromFile("image.png");
try {
$previewImage = $presentation->getImages()->addImage($image);
} finally {
$image->dispose();
}
$firstZoomFrame->setZoomImage($previewImage);
$secondZoomFrame->getLineFormat()->setWidth(5);
$secondZoomFrame->getLineFormat()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 255, 105, 180);
$secondZoomFrame->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor($color);
$secondZoomFrame->getLineFormat()->setDashStyle(LineDashStyle::DashDot);
$secondZoomFrame->setShowBackground(false);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
章節縮放
章節縮放會連結至簡報中的某個章節。可用於重新檢視主題或說明簡報不同部分如何相互連結。

對於章節縮放物件,Aspose.Slides 提供 SectionZoomFrame 類別,以及 ShapeCollection 類別上的方法。
建立章節縮放框格
使用 SectionCollection::addSection 建立章節,然後將回傳的章節傳遞給 ShapeCollection::addSectionZoomFrame。本範例在第一張投影片上放置章節縮放,並將其連結至以彩色投影片開始的章節。框格的位置和尺寸以點為單位指定,簡報另存為 PPTX。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 154, 205, 50);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$section = $presentation->getSections()->addSection("Section 1", $slide);
$sectionZoomFrame = $overviewSlide->getShapes()->addSectionZoomFrame(20, 20, 300, 200, $section);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
使用自訂影像建立章節縮放框格
使用 ShapeCollection::addSectionZoomFrame 的影像參數可在不變更目標章節的情況下顯示自訂預覽。本範例需要本機影像,透過 Images::fromFile 讀取,並以 ImageCollection::addImage 加入。儲存的簡報在第一張投影片上包含一個連結至新建立章節的章節縮放。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Images;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 154, 205, 50);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$image = Images::fromFile("image.png");
try {
$previewImage = $presentation->getImages()->addImage($image);
} finally {
$image->dispose();
}
$section = $presentation->getSections()->addSection("Section 1", $slide);
$sectionZoomFrame = $overviewSlide->getShapes()->addSectionZoomFrame(20, 20, 300, 200, $section, $previewImage);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
變更章節縮放的目標章節
使用 SectionZoomFrame::setTargetSection 可以在不重新建立的情況下重新指向現有的章節縮放。從相同簡報的 Presentation::getSections 集合中選取已填充的章節。指派空的章節會保持目前目標不變,因此在指派前請檢查 Section::getSlidesListOfSection。有關章節的更多資訊,請參閱 Manage Slide Sections。
以下範例載入一個簡報檔案,該檔案必須包含多個已填充的章節、一個名為 Section navigation 的現有章節縮放,以及一個唯一名稱為 Results 的章節。它會在所有投影片中搜尋縮放,並依名稱而非可能因章節重新排序而改變的集合索引找到目的地。如果名稱不唯一,請改用 Section::getSectionId 來識別目的地。
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation("section-zoom.pptx");
try {
$zoom = null;
$slideCount = java_values($presentation->getSlides()->size());
for ($i = 0; $i < $slideCount; $i++) {
$slide = $presentation->getSlides()->get_Item($i);
$shapeCount = java_values($slide->getShapes()->size());
for ($j = 0; $j < $shapeCount; $j++) {
$shape = $slide->getShapes()->get_Item($j);
if (java_instanceof($shape, new JavaClass("com.aspose.slides.ISectionZoomFrame")) && java_values($shape->getName()) === "Section navigation") {
$zoom = $shape;
break;
}
}
if ($zoom != null) {
break;
}
}
$targetSection = null;
$sectionCount = java_values($presentation->getSections()->size());
for ($i = 0; $i < $sectionCount; $i++) {
$section = $presentation->getSections()->get_Item($i);
if (java_values($section->getName()) === "Results") {
$targetSection = $section;
break;
}
}
if ($zoom == null || $targetSection == null) {
echo "The section zoom or destination section was not found.", PHP_EOL;
} else if (java_values($targetSection->getSlidesListOfSection()->size()) == 0) {
echo "The destination section is empty.", PHP_EOL;
} else {
$currentSection = $zoom->getTargetSection();
echo "Current section: " . (java_is_null($currentSection) ? "" : java_values($currentSection->getName())), PHP_EOL;
$zoom->setTargetSection($targetSection);
$presentation->save("section-zoom-updated.pptx", SaveFormat::Pptx);
}
} finally {
$presentation->dispose();
}
格式化章節縮放框格
此範例將章節縮放移動並調整大小為 100 × 75 點,透過 ZoomObject::setZoomImage 指定本機影像,並套用 2.5 點、虛線點劃的棕色邊框。它啟用 ZoomObject::setReturnToParent 以在章節結束後返回原始投影片,停用 ZoomObject::setShowBackground,並將 ZoomObject::setTransitionDuration 設為 1.5 秒。自訂預覽需要本機影像。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Images;
use aspose\slides\LineDashStyle;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 154, 205, 50);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$section = $presentation->getSections()->addSection("Section 1", $slide);
$sectionZoomFrame = $overviewSlide->getShapes()->addSectionZoomFrame(20, 20, 300, 200, $section);
$sectionZoomFrame->setX(100);
$sectionZoomFrame->setY(300);
$sectionZoomFrame->setWidth(100);
$sectionZoomFrame->setHeight(75);
$image = Images::fromFile("image.png");
try {
$previewImage = $presentation->getImages()->addImage($image);
} finally {
$image->dispose();
}
$sectionZoomFrame->setZoomImage($previewImage);
$sectionZoomFrame->setReturnToParent(true);
$sectionZoomFrame->setShowBackground(false);
$sectionZoomFrame->getLineFormat()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 165, 42, 42);
$sectionZoomFrame->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor($color);
$sectionZoomFrame->getLineFormat()->setDashStyle(LineDashStyle::DashDot);
$sectionZoomFrame->getLineFormat()->setWidth(2.5);
$sectionZoomFrame->setTransitionDuration(1.5);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
摘要縮放
摘要縮放提供簡報章節的概覽。在投影片放映期間,您可使用它跳至某個章節、快進或重新檢視主題,而不必依照投影片順序。

對於摘要縮放物件,Aspose.Slides 提供 SummaryZoomFrame、SummaryZoomSection、SummaryZoomSectionCollection 類別,以及 ShapeCollection 類別上的方法。
建立摘要縮放
使用 ShapeCollection::addSummaryZoomFrame 建立簡報章節的概覽。本範例建立四個具有不同投影片背景的章節,並在第一張投影片加入摘要縮放。框格的位置和尺寸以點為單位指定,最終的概覽儲存於 PPTX 簡報中。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 165, 42, 42);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 1", $slide);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 2", $slide);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 127, 255, 0);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 3", $slide);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 0, 100, 0);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 4", $slide);
$summaryZoomFrame = $overviewSlide->getShapes()->addSummaryZoomFrame(150, 50, 300, 200);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
新增與移除摘要縮放章節
摘要縮放會將其 SummaryZoomSection 物件儲存在 SummaryZoomFrame::getSummaryZoomCollection 中。本範例建立兩個章節的概覽,使用 SummaryZoomSectionCollection::addSummaryZoomSection 新增第三個章節,並透過 SummaryZoomSectionCollection::removeSummaryZoomSection 移除第一個章節的條目。移除條目後,簡報的章節及其投影片仍保持完整。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 165, 42, 42);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$firstSection = $presentation->getSections()->addSection("Section 1", $slide);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 2", $slide);
$summaryZoomFrame = $overviewSlide->getShapes()->addSummaryZoomFrame(150, 50, 300, 200);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 127, 255, 0);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$thirdSection = $presentation->getSections()->addSection("Section 3", $slide);
$summaryZoomFrame->getSummaryZoomCollection()->addSummaryZoomSection($thirdSection);
$summaryZoomFrame->getSummaryZoomCollection()->removeSummaryZoomSection($firstSection);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
格式化摘要縮放章節
此範例以零基索引 0 格式化 SummaryZoomFrame::getSummaryZoomCollection 中的第一個條目。它需要本機影像供 ZoomObject::setZoomImage 使用,套用 1.5 點、虛線點劃的黑色邊框,並將 ZoomObject::setTransitionDuration 設為 1.5 秒。將 false 傳遞給 ZoomObject::setReturnToParent 會停用此條目自動返回摘要投影片的功能。
use aspose\slides\BackgroundType;
use aspose\slides\FillType;
use aspose\slides\Images;
use aspose\slides\LineDashStyle;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$overviewSlide = $presentation->getSlides()->get_Item(0);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 165, 42, 42);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor($color);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 1", $slide);
$slide = $presentation->getSlides()->addEmptySlide($overviewSlide->getLayoutSlide());
$slide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$slide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
$slide->getBackground()->setType(BackgroundType::OwnBackground);
$presentation->getSections()->addSection("Section 2", $slide);
$summaryZoomFrame = $overviewSlide->getShapes()->addSummaryZoomFrame(150, 50, 300, 200);
$summarySection = $summaryZoomFrame->getSummaryZoomCollection()->get_Item(0);
$image = Images::fromFile("image.png");
try {
$previewImage = $presentation->getImages()->addImage($image);
} finally {
$image->dispose();
}
$summarySection->setZoomImage($previewImage);
$summarySection->setReturnToParent(false);
$summarySection->getLineFormat()->getFillFormat()->setFillType(FillType::Solid);
$summarySection->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
$summarySection->getLineFormat()->setDashStyle(LineDashStyle::DashDot);
$summarySection->getLineFormat()->setWidth(1.5);
$summarySection->setTransitionDuration(1.5);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
常見問題
我可以控制在顯示目標後返回「父」投影片嗎?
可以。呼叫 ZoomObject::setReturnToParent 並傳入 true,即可在顯示目標內容後返回原始投影片。
我可以調整縮放過渡的「速度」或持續時間嗎?
可以。使用 ZoomObject::setTransitionDuration 以秒為單位控制過渡時間。
簡報中可包含的縮放物件數量有限制嗎?
文件中未列出硬性的 API 限制。實際限制取決於簡報的整體複雜度與檢視器的效能。雖然可以加入大量縮放框格,但仍需考量檔案大小與渲染時間。