Android에서 프레젠테이션의 슬라이드 섹션 관리
소개
섹션은 연속된 슬라이드를 슬라이드 내용을 변경하지 않고 이름이 지정된 그룹으로 조직합니다. Aspose.Slides for Android via Java를 사용하면 Presentation.getSections 메서드를 통해 섹션을 만들고, 순서를 변경하고, 이름을 바꾸고, 검사하고, 제거할 수 있습니다.
섹션은 특히 다음과 같은 경우에 유용합니다:
- 대형 프레젠테이션을 논리적인 주제나 장으로 나누어야 할 때;
- 다른 슬라이드 그룹을 서로 다른 협업자에게 할당할 때;
- 슬라이드를 그룹으로 처리, 이동 또는 병합해야 할 때.
그룹화된 슬라이드의 목적을 설명하는 간결한 섹션 이름을 선택하세요. 섹션은 프레젠테이션 구조의 일부이므로 슬라이드 위치에서 추론하지 말고 섹션 API를 사용하여 멤버십을 확인하십시오.
섹션 만들기 및 관리
ISectionCollection.addSection을 사용하여 이름과 시작 슬라이드를 지정해 섹션을 만들 수 있습니다. Aspose.Slides는 현재 프레젠테이션의 섹션 구조를 기반으로 어떤 슬라이드가 해당 섹션에 속하는지 판단합니다.
동일한 ISectionCollection을 사용하여 다음을 수행할 수 있습니다:
- ISectionCollection.reorderSectionWithSlides를 사용하여 섹션과 해당 슬라이드를 함께 이동합니다;
- ISectionCollection.removeSection만 사용하여 섹션 정의만 제거하고 슬라이드는 유지합니다;
- ISectionCollection.removeSectionWithSlides를 사용하여 섹션과 그 슬라이드를 모두 제거합니다;
- ISectionCollection.appendEmptySection를 사용하여 끝에 빈 섹션을 추가합니다.
다음 예제는 두 개의 섹션을 만들고, 그 중 하나를 이동한 뒤 슬라이드와 함께 제거하고, 빈 섹션을 추가합니다:
import com.aspose.slides.ILayoutSlide;
import com.aspose.slides.ISection;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
Presentation presentation = new Presentation();
try {
ISlide titleSlide = presentation.getSlides().get_Item(0);
ILayoutSlide layoutSlide = presentation.getLayoutSlides().get_Item(0);
presentation.getSlides().addEmptySlide(layoutSlide);
ISlide resultsSlide = presentation.getSlides().addEmptySlide(layoutSlide);
presentation.getSlides().addEmptySlide(layoutSlide);
presentation.getSections().addSection("Introduction", titleSlide);
ISection resultsSection = presentation.getSections().addSection("Results", resultsSlide);
presentation.getSections().reorderSectionWithSlides(resultsSection, 0);
presentation.getSections().removeSectionWithSlides(resultsSection);
presentation.getSections().appendEmptySection("Appendix");
} finally {
presentation.dispose();
}
이러한 작업 후 프레젠테이션에는 슬라이드가 포함된 Introduction 섹션과 빈 Appendix 섹션이 남습니다. Results 섹션과 해당 슬라이드는 제거되었습니다.
섹션 이름 바꾸기
섹션의 이름을 바꾸려면 해당 섹션의 ISection.setName 메서드를 호출하면 됩니다. 섹션의 슬라이드와 위치는 그대로 유지됩니다.
다음 예제는 섹션을 만든 뒤 이름을 변경합니다:
import com.aspose.slides.ISection;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
ISection section = presentation.getSections().addSection("Overview", slide);
section.setName("Introduction");
} finally {
presentation.dispose();
}
섹션에서 슬라이드 가져오기
Presentation.getSections 메서드는 반복할 수 있는 ISectionCollection을 반환합니다. 각 ISection에 대해 ISection.getSlidesListOfSection을 호출하면 현재 해당 섹션에 속한 슬라이드를 얻을 수 있습니다. 이 메서드는 슬라이드 수, 인덱스 접근 및 반복을 제공하는 ISectionSlideCollection을 반환합니다.
다음 예제는 두 개의 채워진 섹션과 하나의 빈 섹션을 만든 뒤 각 섹션의 name, identifier, starting slide, 슬라이드 수 및 슬라이드 번호를 출력합니다. 첫 슬라이드를 읽기 위해 ISectionSlideCollection.get_Item을 사용하고, 향상된 for 문으로 모든 슬라이드를 처리합니다. 빈 섹션의 경우 반환된 컬렉션 크기가 0이므로 메서드가 호출되지 않으며 반복도 수행되지 않습니다.
import com.aspose.slides.ILayoutSlide;
import com.aspose.slides.ISection;
import com.aspose.slides.ISectionSlideCollection;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
Presentation presentation = new Presentation();
try {
ISlide firstSlide = presentation.getSlides().get_Item(0);
ILayoutSlide layoutSlide = presentation.getLayoutSlides().get_Item(0);
presentation.getSlides().addEmptySlide(layoutSlide);
ISlide thirdSlide = presentation.getSlides().addEmptySlide(layoutSlide);
presentation.getSections().addSection("Introduction", firstSlide);
presentation.getSections().addSection("Details", thirdSlide);
presentation.getSections().appendEmptySection("Appendix");
for (ISection section : presentation.getSections()) {
ISectionSlideCollection sectionSlides = section.getSlidesListOfSection();
String startingSlide = section.getStartedFromSlide() == null ? "none" : Integer.toString(section.getStartedFromSlide().getSlideNumber());
System.out.println("Section: " + section.getName());
System.out.println("ID: " + section.getSectionId());
System.out.println("Starting slide: " + startingSlide);
System.out.println("Slide count: " + sectionSlides.size());
if (sectionSlides.size() > 0) {
System.out.println("First slide via get_Item: " + sectionSlides.get_Item(0).getSlideNumber());
}
System.out.print("Slide numbers:");
for (ISlide slide : sectionSlides) {
System.out.print(" " + slide.getSlideNumber());
}
System.out.println();
}
} finally {
presentation.dispose();
}
섹션 멤버십은 프레젠테이션의 섹션 구조에 따라 결정됩니다. ISection.getStartedFromSlide과 슬라이드 인덱스, 다음 섹션의 시작 슬라이드만으로 섹션 범위를 수동으로 계산하지 마십시오.
구조적 편집은 섹션에 대해 반환되는 슬라이드와 슬라이드 번호 모두를 변경할 수 있습니다. 여기에는 슬라이드 재정렬, 슬라이드 복제, 섹션과 슬라이드 이동, 슬라이드 제거 및 섹션 제거가 포함됩니다. 다음 예제는 이러한 변경이 발생할 때마다 ISection.getSlidesListOfSection을 호출해 이전 경계에 대한 가정을 유지하지 않습니다.
import com.aspose.slides.ILayoutSlide;
import com.aspose.slides.ISection;
import com.aspose.slides.ISectionSlideCollection;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
import java.util.function.BiConsumer;
Presentation presentation = new Presentation();
try {
ISlide firstSlide = presentation.getSlides().get_Item(0);
ILayoutSlide layoutSlide = presentation.getLayoutSlides().get_Item(0);
presentation.getSlides().addEmptySlide(layoutSlide);
ISlide thirdSlide = presentation.getSlides().addEmptySlide(layoutSlide);
presentation.getSlides().addEmptySlide(layoutSlide);
ISection firstSection = presentation.getSections().addSection("First", firstSlide);
ISection secondSection = presentation.getSections().addSection("Second", thirdSlide);
BiConsumer<String, ISection> printSectionSlides = (label, section) -> {
ISectionSlideCollection sectionSlides = section.getSlidesListOfSection();
System.out.printf("%s (%d slides):", label, sectionSlides.size());
for (ISlide slide : sectionSlides) {
System.out.print(" " + slide.getSlideNumber());
}
System.out.println();
};
printSectionSlides.accept("Initially", firstSection);
ISectionSlideCollection slidesBeforeClone = firstSection.getSlidesListOfSection();
presentation.getSlides().addClone(slidesBeforeClone.get_Item(0), firstSection);
printSectionSlides.accept("After cloning into the section", firstSection);
ISectionSlideCollection slidesBeforeReorder = firstSection.getSlidesListOfSection();
int firstSectionPosition = slidesBeforeReorder.get_Item(0).getSlideNumber() - 1;
presentation.getSlides().reorder(firstSectionPosition, slidesBeforeReorder.get_Item(slidesBeforeReorder.size() - 1));
printSectionSlides.accept("After reordering slides", firstSection);
presentation.getSections().reorderSectionWithSlides(firstSection, 1);
printSectionSlides.accept("After moving the section", firstSection);
ISectionSlideCollection slidesBeforeRemoval = firstSection.getSlidesListOfSection();
presentation.getSlides().remove(slidesBeforeRemoval.get_Item(0));
printSectionSlides.accept("After removing a slide", firstSection);
presentation.getSections().removeSectionWithSlides(secondSection);
for (ISection section : presentation.getSections()) {
printSectionSlides.accept("Remaining section", section);
}
} finally {
presentation.dispose();
}
슬라이드나 섹션이 재정렬, 복제, 이동 또는 제거될 때마다 ISection.getSlidesListOfSection을 다시 호출하십시오. 이렇게 하면 이후 처리가 현재 프레젠테이션 구조와 일치하게 유지됩니다.
PPT (PowerPoint 97–2003) 형식은 섹션 메타데이터를 보존하지 않습니다. PPTX와 같이 섹션을 지원하는 형식으로 작업 흐름을 사용하세요; PPT로 변환하면 이후 반복에 필요한 섹션 구조가 사라집니다.
FAQ
PPT (PowerPoint 97–2003) 형식으로 저장할 때 섹션이 보존되나요?
아니요. PPT 형식은 섹션 메타데이터를 지원하지 않으므로 .ppt로 저장하면 섹션 그룹화가 손실됩니다.
전체 섹션을 “숨길” 수 있나요?
아니요. 섹션에는 표시/숨김 상태가 없습니다. 섹션 내용을 숨기려면 해당 섹션의 각 슬라이드에 대해 ISlide.setHidden를 호출하세요.
특정 슬라이드를 포함하고 있는 섹션을 어떻게 찾나요?
Presentation.getSections이 반환하는 컬렉션을 반복하고, 각 섹션에 대해 ISection.getSlidesListOfSection을 호출한 뒤 반환된 슬라이드와 대상 슬라이드를 비교하십시오. 비어 있지 않은 섹션의 경우 ISection.getStartedFromSlide이 첫 슬라이드를 반환하고, 빈 섹션의 경우 null을 반환합니다.